Class: Synchroniser::Config::Params
- Inherits:
-
Object
- Object
- Synchroniser::Config::Params
- Defined in:
- lib/synchroniser/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #build_container(container) ⇒ Object
- #build_ingestors ⇒ Object
- #get_sync ⇒ Object
-
#initialize(file_name, ingestor_name, defaults = {}) ⇒ Params
constructor
A new instance of Params.
Constructor Details
#initialize(file_name, ingestor_name, defaults = {}) ⇒ Params
Returns a new instance of Params.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/synchroniser/config.rb', line 7 def initialize(file_name, ingestor_name, defaults={}) file_path = "#{RAILS_ROOT}#{file_name}" config = YAML::load(File.open(file_path)) begin @config = config[RAILS_ENV] rescue @config = nil raise ArgumentError, "Unable to find the #{environment} stanza for #{ingestor_name}' in the configuration file supplied" end if @config.nil? raise ArgumentError, "Unable to find the stanza '#{ingestor_name}' in the configuration file supplied" end defaults['group'] ||= @config["params"]["container"]["defaults"]['group'] defaults['group'] ||= ingestor_name @config["params"]["container"]["defaults"].merge!(defaults) unless defaults.empty? end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/synchroniser/config.rb', line 5 def config @config end |
Instance Method Details
#build_container(container) ⇒ Object
39 40 41 |
# File 'lib/synchroniser/config.rb', line 39 def build_container(container) eval "#{container['object']}.new(container['defaults'])" end |
#build_ingestors ⇒ Object
34 35 36 37 |
# File 'lib/synchroniser/config.rb', line 34 def build_ingestors() require @config['ingestor'] + "_ingestor.rb" eval("#{@config['ingestor'].camelize}Ingestor.new").strategise(@config['params']['url']) end |
#get_sync ⇒ Object
28 29 30 31 32 |
# File 'lib/synchroniser/config.rb', line 28 def get_sync container = build_container(@config['params']['container']) ingestors = build_ingestors() Synchroniser.new(container, ingestors) end |