Class: Conflate::Conflation
- Inherits:
-
Object
- Object
- Conflate::Conflation
- Defined in:
- lib/conflate/conflation.rb
Instance Attribute Summary collapse
-
#config_object ⇒ Object
Returns the value of attribute config_object.
-
#yaml_path ⇒ Object
Returns the value of attribute yaml_path.
Instance Method Summary collapse
-
#apply ⇒ Object
Public: Add the contents of the YAML file to the config object.
-
#initialize(yaml_path, config_object) ⇒ Conflation
constructor
Public: Initialize a new Conflation.
-
#name ⇒ Object
Public: The name of the conflation, based on the YAML file name.
Constructor Details
#initialize(yaml_path, config_object) ⇒ Conflation
Public: Initialize a new Conflation
yaml_path - Path to the YAML file to read config information from config_object - Object to receive the configuration values (e.g., Rails.application.config)
13 14 15 16 |
# File 'lib/conflate/conflation.rb', line 13 def initialize(yaml_path, config_object) self.yaml_path = yaml_path self.config_object = config_object end |
Instance Attribute Details
#config_object ⇒ Object
Returns the value of attribute config_object.
7 8 9 |
# File 'lib/conflate/conflation.rb', line 7 def config_object @config_object end |
#yaml_path ⇒ Object
Returns the value of attribute yaml_path.
7 8 9 |
# File 'lib/conflate/conflation.rb', line 7 def yaml_path @yaml_path end |
Instance Method Details
#apply ⇒ Object
Public: Add the contents of the YAML file to the config object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/conflate/conflation.rb', line 19 def apply if config_object.respond_to?(name) && !config_object.public_send(name).nil? # doing this to properly handle the slightly different behaviors of # OpenStruct (which does respond to unassigned attributes) or the # Rails.application.config object (which doesn't) warn "#{config_object.class} already has a #{config_object.public_send(name).class} for the key '#{name}'. Skipping conflating it with the contents of #{File.basename yaml_path}." return # so don't set it end config_object.public_send "#{name}=", data end |
#name ⇒ Object
Public: The name of the conflation, based on the YAML file name
Returns a String
34 35 36 |
# File 'lib/conflate/conflation.rb', line 34 def name File.basename(yaml_path, ".yml") end |