PHP 8.2.31
Preview: add.rb Size: 2.06 KB
/proc/thread-self/root/opt/alt/ruby40/share/gems/gems/bundler-4.0.10/lib/bundler/cli/add.rb

# frozen_string_literal: true

module Bundler
  class CLI::Add
    attr_reader :gems, :options, :version

    def initialize(options, gems)
      @gems = gems
      @options = options
      @options[:group] = options[:group].split(",").map(&:strip) unless options[:group].nil?
      @version = options[:version].split(",").map(&:strip) unless options[:version].nil?
    end

    def run
      Bundler.ui.level = "warn" if options[:quiet]

      validate_options!
      inject_dependencies
      perform_bundle_install unless options["skip-install"]
    end

    private

    def perform_bundle_install
      Installer.install(Bundler.root, Bundler.definition)
      Bundler.load.cache if Bundler.app_cache.exist?
    end

    def inject_dependencies
      dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) }

      Injector.inject(dependencies,
        conservative_versioning: options[:version].nil?, # Perform conservative versioning only when version is not specified
        optimistic: options[:optimistic],
        strict: options[:strict])
    end

    def validate_options!
      raise InvalidOption, "You cannot specify `--git` and `--github` at the same time." if options["git"] && options["github"]

      unless options["git"] || options["github"]
        raise InvalidOption, "You cannot specify `--branch` unless `--git` or `--github` is specified." if options["branch"]

        raise InvalidOption, "You cannot specify `--ref` unless `--git` or `--github` is specified." if options["ref"]
      end

      raise InvalidOption, "You cannot specify `--branch` and `--ref` at the same time." if options["branch"] && options["ref"]

      raise InvalidOption, "You cannot specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic]

      # raise error when no gems are specified
      raise InvalidOption, "Please specify gems to add." if gems.empty?

      version.to_a.each do |v|
        raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN.match?(v.to_s)
      end
    end
  end
end

Directory Contents

Dirs: 1 × Files: 26

Name Size Perms Modified Actions
doctor DIR
- drwxr-xr-x 2026-06-09 07:03:24
Edit Download
2.06 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.77 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
711 B lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.21 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
608 B lrw-r--r-- 2026-05-21 12:15:22
Edit Download
5.23 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
6.01 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.10 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.44 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
3.10 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
902 B lrw-r--r-- 2026-05-21 12:15:22
Edit Download
16.97 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
2.89 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.28 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
4.61 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.31 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
2.75 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
2.81 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.14 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
9.11 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.27 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
1.83 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
2.13 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
351 B lrw-r--r-- 2026-05-21 12:15:22
Edit Download
2.11 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download
4.16 KB lrw-r--r-- 2026-05-21 12:15:22
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).