Class: VitaminedGems::VitaminedGem

Inherits:
Object
  • Object
show all
Defined in:
lib/vitamined-gems.rb

Instance Method Summary collapse

Constructor Details

#initialize(rails_configuration, vitamins) ⇒ VitaminedGem

Returns a new instance of VitaminedGem.



32
33
34
35
# File 'lib/vitamined-gems.rb', line 32

def initialize(rails_configuration, vitamins)
  @rails_configuration = rails_configuration
  @vitamins = vitamins
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(vitamin_name, gem_name, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vitamined-gems.rb', line 41

def method_missing(vitamin_name, gem_name, options = {})
  if vitamin = @vitamins[vitamin_name] 
    options = if vitamin.is_a? Hash
      vitamin.merge(options)
    else
      vitamin.call(gem_name, options).merge(options)
    end                
    @rails_configuration.gem(gem_name, options) 
  else
    raise UnknownVitamin.new(vitamin_name)
  end
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/vitamined-gems.rb', line 37

def respond_to?(method)
  @vitamins.has_key?(method.to_sym) || super.respond_to?(method)
end