Class: YamlConfiguration::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_configuration/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_configuration, parent = nil, name = nil) ⇒ Configuration

Returns a new instance of Configuration.



5
6
7
8
9
10
11
# File 'lib/yaml_configuration/configuration.rb', line 5

def initialize(hash_configuration, parent=nil, name=nil)
  @config = hash_configuration
  @name = name
  @parent = parent
  parent_preprocessor = @parent.placeholders_preprocessor unless @parent.nil?
  @placeholders_preprocessor = parent_preprocessor || PlaceholdersPreprocessor.new(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/yaml_configuration/configuration.rb', line 22

def method_missing(method, *args, &block)
  method_name = method.to_s
  if asking_if_setting_exist(method_name)
    setting_exist?(method_name)
  elsif setting_exist?(method_name)
    return_value_of_setting(method_name)
  else
    raise "The setting '#{full_name(method_name)}' is not present in the configuration"
  end
end

Instance Attribute Details

#placeholders_preprocessorObject (readonly)

Returns the value of attribute placeholders_preprocessor.



3
4
5
# File 'lib/yaml_configuration/configuration.rb', line 3

def placeholders_preprocessor
  @placeholders_preprocessor
end

Instance Method Details

#full_name(setting_name) ⇒ Object



13
14
15
# File 'lib/yaml_configuration/configuration.rb', line 13

def full_name(setting_name)
  (hierarchy + [setting_name]).join('.')
end

#hierarchyObject



17
18
19
20
# File 'lib/yaml_configuration/configuration.rb', line 17

def hierarchy
  return @parent.hierarchy + [@name] unless @parent.nil?
  []
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/yaml_configuration/configuration.rb', line 33

def respond_to_missing?(method, *)
  asking_if_setting_exist(method.to_s) || setting_exist?(method.to_s) || super
end