Class: Warbler::Gems
- Inherits:
-
Hash
- Object
- Hash
- Warbler::Gems
- Defined in:
- lib/warbler/gems.rb
Overview
A set of gems. This only exists to allow expected operations to be used to add gems, and for backwards compatibility. It would be easier to just use a hash.
Constant Summary collapse
- ANY_VERSION =
nil
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<<(gem) ⇒ Object
- #full_name_for(name, gem_dependencies) ⇒ Object
-
#initialize(gems = nil) ⇒ Gems
constructor
A new instance of Gems.
- #specs(gem_dependencies) ⇒ Object
Constructor Details
#initialize(gems = nil) ⇒ Gems
Returns a new instance of Gems.
15 16 17 18 19 20 21 |
# File 'lib/warbler/gems.rb', line 15 def initialize(gems = nil) if gems.is_a?(Hash) self.merge!(gems) elsif gems.is_a?(Array) gems.each {|gem| self << gem } end end |
Instance Method Details
#+(other) ⇒ Object
28 29 30 31 32 |
# File 'lib/warbler/gems.rb', line 28 def +(other) @specs = nil other.each {|g| self[g] ||= ANY_VERSION } self end |
#-(other) ⇒ Object
34 35 36 37 38 |
# File 'lib/warbler/gems.rb', line 34 def -(other) @specs = nil other.each {|g| self.delete(g)} self end |
#<<(gem) ⇒ Object
23 24 25 26 |
# File 'lib/warbler/gems.rb', line 23 def <<(gem) @specs = nil self[gem] ||= ANY_VERSION end |
#full_name_for(name, gem_dependencies) ⇒ Object
40 41 42 43 |
# File 'lib/warbler/gems.rb', line 40 def full_name_for(name, gem_dependencies) spec = specs(gem_dependencies).detect{ |spec| spec.name == name } spec.nil? ? name : spec.full_name end |
#specs(gem_dependencies) ⇒ Object
45 46 47 |
# File 'lib/warbler/gems.rb', line 45 def specs(gem_dependencies) @specs ||= map { |gem, version| find_single_gem_files(gem_dependencies, gem, version) }.flatten.compact end |