Class: Warbler::Gems

Inherits:
Hash
  • Object
show all
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.

Instance Method Summary collapse

Constructor Details

#initialize(gems = nil) ⇒ Gems

Returns a new instance of Gems.



16
17
18
19
20
21
22
# File 'lib/warbler/gems.rb', line 16

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



29
30
31
32
33
# File 'lib/warbler/gems.rb', line 29

def +(other)
  @specs = nil
  other.each {|g| self[g] ||= ANY_VERSION }
  self
end

#-(other) ⇒ Object



35
36
37
38
39
# File 'lib/warbler/gems.rb', line 35

def -(other)
  @specs = nil
  other.each {|g| self.delete(g)}
  self
end

#<<(gem) ⇒ Object



24
25
26
27
# File 'lib/warbler/gems.rb', line 24

def <<(gem)
  @specs = nil
  self[gem] ||= ANY_VERSION
end

#full_name_for(name, gem_dependencies) ⇒ Object



41
42
43
44
# File 'lib/warbler/gems.rb', line 41

def full_name_for(name, gem_dependencies)
  gem_spec = specs(gem_dependencies).detect{ |spec| spec.name == name }
  gem_spec.nil? ? name : gem_spec.full_name
end

#specs(gem_dependencies) ⇒ Object



46
47
48
# File 'lib/warbler/gems.rb', line 46

def specs(gem_dependencies)
  @specs ||= map { |gem, version| find_single_gem_files(gem_dependencies, gem, version) }.flatten.compact
end