module Flor::Conf

Constants

LOG_ALL_KEYS
LOG_DBG_KEYS

Public Class Methods

get_class(conf, key) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Protected Class Methods

interpret_env() click to toggle source
# File lib/flor/conf.rb, line 152
def interpret_env

  h = {}
  u = ENV['FLOR_UNIT']
  h['unit'] = u if u

  h
end