class Cl::Config::Env

Constants

FALSE
TRUE

Public Instance Methods

load() click to toggle source
# File lib/cl/config/env.rb, line 11
def load
  vars = opts.map { |cmd, opts| vars(cmd, opts) }
  merge(*vars.flatten.compact)
end

Private Instance Methods

cast(value) click to toggle source
# File lib/cl/config/env.rb, line 38
def cast(value)
  case value
  when TRUE
    true
  when FALSE
    false
  when ''
    false
  else
    value
  end
end
key(*keys) click to toggle source
# File lib/cl/config/env.rb, line 30
def key(*keys)
  [name.upcase, *keys].join('_').upcase.sub('-', '_')
end
only(hash, *keys) click to toggle source
# File lib/cl/config/env.rb, line 34
def only(hash, *keys)
  hash.select { |key, _| keys.include?(key) }.to_h
end
opts() click to toggle source
# File lib/cl/config/env.rb, line 22
def opts
  Cmd.registry.map { |key, cmd| [key, cmd.opts.map(&:name) - [:help]] }
end
var(cmd, opt, key) click to toggle source
# File lib/cl/config/env.rb, line 26
def var(cmd, opt, key)
  { cmd => { opt => cast(ENV[key]) } } if ENV[key]
end
vars(cmd, opts) click to toggle source
# File lib/cl/config/env.rb, line 18
def vars(cmd, opts)
  opts.map { |opt| var(cmd, opt, key(cmd, opt)) }
end