Class: Bundler::CLI::Inject
- Inherits:
-
Object
- Object
- Bundler::CLI::Inject
- Defined in:
- lib/bundler/cli/inject.rb
Instance Attribute Summary collapse
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(options, name, version, gems) ⇒ Inject
constructor
A new instance of Inject.
- #run ⇒ Object
Constructor Details
#initialize(options, name, version, gems) ⇒ Inject
Returns a new instance of Inject.
4 5 6 7 8 9 |
# File 'lib/bundler/cli/inject.rb', line 4 def initialize(, name, version, gems) @options = @name = name @version = version @gems = gems end |
Instance Attribute Details
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
3 4 5 |
# File 'lib/bundler/cli/inject.rb', line 3 def gems @gems end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bundler/cli/inject.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/bundler/cli/inject.rb', line 3 def @options end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/bundler/cli/inject.rb', line 3 def version @version end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bundler/cli/inject.rb', line 11 def run # The required arguments allow Thor to give useful feedback when the arguments # are incorrect. This adds those first two arguments onto the list as a whole. gems.unshift(version).unshift(name) # Build an array of Dependency objects out of the arguments deps = [] gems.each_slice(2) do |gem_name, gem_version| deps << Bundler::Dependency.new(gem_name, gem_version) end added = Injector.inject(deps) if added.any? Bundler.ui.confirm "Added to Gemfile:" Bundler.ui.confirm added.map{ |g| " #{g}" }.join("\n") else Bundler.ui.confirm "All injected gems were already present in the Gemfile" end end |