Module: SweetyBacky::OptsReader

Defined in:
lib/sweety_backy/opts_reader.rb

Class Method Summary collapse

Class Method Details

.log_configuration(opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sweety_backy/opts_reader.rb', line 30

def self.log_configuration( opts )
  SweetyBacky::Utils::log "configuration:"
  SweetyBacky::Utils::log "------------"
  opts.each_pair do |key, value|
    if( value.is_a? Array )
      SweetyBacky::Utils::log "#{key}: #{value.join(' | ')}"
    elsif( value.is_a? Hash )
      value.each_pair do |key2, value2|
        SweetyBacky::Utils::log "#{key} => #{key2}: #{value2}"
      end
    else
      SweetyBacky::Utils::log "#{key}: #{value}"
    end
  end
end

.read_opts(conf_path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sweety_backy/opts_reader.rb', line 3

def self.read_opts( conf_path )
  SweetyBacky::Utils::log "conf_path: #{conf_path}"

  opts = YAML.load( File.read( conf_path ) )
  new_opts = {}
  
  # symbolize keys
  opts.keys.each do |key|        
    
    if( opts[key].is_a? Hash )
      new_opts[key.to_sym] = {}
      opts[key].keys.each do |key2|
        new_opts[key.to_sym][key2.to_sym] = opts[key][key2]
      end
    else
      new_opts[key.to_sym] = opts[key]
    end

  end
  
  log_configuration( new_opts )

  # TODO: test all options are ok

  return new_opts
end