Module: Flor::Conf

Defined in:
lib/flor/conf.rb

Constant Summary collapse

LOG_DBG_KEYS =
%w[ dbg msg err src tree tree_rw run ]
LOG_ALL_KEYS =
%w[ all log sto ] + LOG_DBG_KEYS

Class Method Summary collapse

Class Method Details

.get_class(conf, key) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/flor/conf.rb', line 107

def get_class(conf, key)

  case v = conf[key]
  when Class then v
  when String then Flor.const_lookup(v)
  else nil
  end
end

.interpret_flor_debug(c) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/flor/conf.rb', line 119

def interpret_flor_debug(c)

  plus, minus = [
    c['flor_debug'], c[:debug], c['debug'], ENV['FLOR_DEBUG'] ]
      .collect { |v| (v || '').split(/\s*,\s*/) }
      .flatten(1)
      .partition { |v| v[0, 1] != '-' }
  plus = plus.collect { |v| v[0, 1] == '+' ? v[1..-1] : v }
  minus = minus.collect { |v| v[0, 1] == '-' ? v[1..-1] : v }
  a = plus - minus

  h =
    a.inject({}) { |hh, kv|
      k, v = kv.split(':')
      k = 'sto' if k == 'db'
      k = "log_#{k}" if LOG_ALL_KEYS.include?(k)
      hh[k] = v ? JSON.parse(v) : true
      hh }
  LOG_ALL_KEYS.each { |k| h["log_#{k}"] = 1 } if h['log_all']
  LOG_DBG_KEYS.each { |k| h["log_#{k}"] = 1 } if h['log_dbg']

  h['log_colours'] = true \
    if a.include?('colours') || a.include?('colors')
      # LOG_DEBUG=colours forces colors

  h['log_out'] = 'stdout' if h.delete('stdout')
  h['log_out'] = 'stderr' if h.delete('stderr')

  h
end

.prepare(conf, over_conf) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/flor/conf.rb', line 82

def prepare(conf, over_conf)

  c =
    case conf
    when String then Flor::ConfExecutor.interpret_path_or_source(conf)
    when Hash then Flor.to_string_keyed_hash(conf)
    else conf
    end

  fail ArgumentError.new(
    "cannot extract conf out of #{c.inspect} (#{conf.class})"
  ) unless c.is_a?(Hash)

  unless c['conf'] == true
    #
    # don't read FLOR_DEBUG if this executor is only meant to read
    # the conf

    c.merge!(interpret_flor_debug(c))
    c.merge!(interpret_env)
  end

  c.merge!(over_conf)
end