class Environmentor::Mappers::Env
Public Class Methods
new(prefix: '')
click to toggle source
# File lib/environmentor/mappers/env.rb, line 11 def initialize(prefix: '') @prefix = prefix end
to_sym()
click to toggle source
# File lib/environmentor/mappers/env.rb, line 7 def self.to_sym :env end
Public Instance Methods
human_attr_location(attr, **opts)
click to toggle source
# File lib/environmentor/mappers/env.rb, line 30 def human_attr_location(attr, **opts) attr_env_var_name attr, **opts end
human_description()
click to toggle source
# File lib/environmentor/mappers/env.rb, line 25 def human_description # TODO: localise "environment" end
value_for_attribute(attr, **opts)
click to toggle source
# File lib/environmentor/mappers/env.rb, line 15 def value_for_attribute(attr, **opts) k = attr_env_var_name(attr, **opts) if ENV.has_key?(k) ENV[k] else raise Environmentor::Mappers::ValueNotFound end end
Protected Instance Methods
attr_env_var_name(attr, name: nil, full_name: nil)
click to toggle source
# File lib/environmentor/mappers/env.rb, line 36 def attr_env_var_name(attr, name: nil, full_name: nil) k = full_name || (attr.namespace_chain.map { |s| self.class.opts_from_mappers_hash(s.opts)[:prefix] || s.name && (s.name.to_s.upcase + '_') }.compact.join('') + (name || attr.name.to_s.upcase)) @prefix + k end