Class: Synchroniser::Config::Params

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject

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_ingestorsObject



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_syncObject



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