Class: Coconut::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/coconut/config.rb

Class Method Summary collapse

Class Method Details

.const_missing(name) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/coconut/config.rb', line 43

def self.const_missing(name)
  if property?(name.downcase)
    define_constant(name)
    return @config[name.downcase]
  end
  super
end

.respond_to?(name) ⇒ Boolean

Coconut::Config objects will respond to methods if its name is equal to any of the configured properties. This method is redefined to make its behaviour consistent with Coconut::Config#method_missing

Returns:

  • (Boolean)

    whether a config object knows how to respond to method “name”



15
16
17
# File 'lib/coconut/config.rb', line 15

def self.respond_to?(name)
  property?(name) or super
end

.to_hashHash

Returns a Hash representation of the configuration object.

Returns:

  • (Hash)

    a Hash representation of the configuration object



20
21
22
# File 'lib/coconut/config.rb', line 20

def self.to_hash
  @properties.dup
end

.with(properties) ⇒ Object



3
4
5
6
7
8
# File 'lib/coconut/config.rb', line 3

def self.with(properties)
  dup.tap do |new_config|
    new_config.instance_variable_set('@properties', properties)
    new_config.instance_variable_set('@config', config_from(properties))
  end
end