diff options
author | Guillermo Guerrero <wolf.fox1985@gmail.com> | 2019-04-12 12:37:03 +0200 |
---|---|---|
committer | Guillermo Guerrero <wolf.fox1985@gmail.com> | 2019-04-12 12:37:03 +0200 |
commit | 7c28917f602efa3480bb9298d9d3541310dd8e90 (patch) | |
tree | b9c8a1745ab240858bb331e8ebeb06a08a9abeaf | |
parent | 8b54f74000a1c869cd7c9ebeac3e021d9e65c549 (diff) | |
download | bundler-7c28917f602efa3480bb9298d9d3541310dd8e90.tar.gz |
Run method refactors, move to functions.
-rw-r--r-- | lib/bundler/cli/add.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index b7e3196164..05d6a18572 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -12,25 +12,37 @@ module Bundler end def run - raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic] + validate_options! + inject_dependencies + perform_bundle_install unless options["skip-install"] + end - # raise error when no gems are specified - raise InvalidOption, "Please specify gems to add." if gems.empty? + private - unless version.nil? - version.each do |v| - raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s - end - end + def perform_bundle_install + Installer.install(Bundler.root, Bundler.definition) + 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 - Installer.install(Bundler.root, Bundler.definition) unless options["skip-install"] + def validate_options! + raise InvalidOption, "You can not 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? + + unless version.nil? + version.each do |v| + raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s + end + end end end end |