class Enver::Loader
Attributes
attributes[R]
Public Class Methods
new(env, prefix = '', &block)
click to toggle source
# File lib/enver/loader.rb, line 7 def initialize(env, prefix = '', &block) @env = env @prefix = prefix @attributes = OpenStruct.new instance_eval(&block) if block end
Public Instance Methods
array(*args)
click to toggle source
# File lib/enver/loader.rb, line 51 def array(*args) value(*args) do |v, options| pattern = options[:pattern] || ',' limit = options[:limit] || 0 v.split(pattern, limit) end end
boolean(*args)
click to toggle source
# File lib/enver/loader.rb, line 44 def boolean(*args) value(*args) do |v, options| true_values = options[:true_values] || %w(1 t true y yes) true_values.include?(v) end end
float(*args)
click to toggle source
# File lib/enver/loader.rb, line 38 def float(*args) value(*args) do |v| Float(v) end end
integer(*args)
click to toggle source
# File lib/enver/loader.rb, line 32 def integer(*args) value(*args) do |v| Integer(v) end end
partial(*args, &block)
click to toggle source
# File lib/enver/loader.rb, line 59 def partial(*args, &block) options = extract_options! args name = args.shift env_prefix = args.shift || "#{name.to_s.upcase}_" store name, Loader.new(@env, with_prefix(env_prefix), &block).attributes end
string(*args)
click to toggle source
# File lib/enver/loader.rb, line 26 def string(*args) value(*args) do |v| v end end
value(*args) { |value, options| ... }
click to toggle source
# File lib/enver/loader.rb, line 14 def value(*args) options = extract_options! args has_default = options.key? :default name = args.shift env_name = args.shift || name.to_s.upcase value = fetch env_name, options value = yield value, options if !has_default && block_given? store name, value end
Private Instance Methods
extract_options!(args)
click to toggle source
# File lib/enver/loader.rb, line 68 def extract_options!(args) args.last.is_a?(::Hash) ? args.pop : {} end
fetch(env_name, options = {})
click to toggle source
# File lib/enver/loader.rb, line 80 def fetch(env_name, options = {}) env_name = with_prefix(env_name) if options.has_key? :default @env.fetch(env_name, options[:default]) else @env.fetch(env_name) end end
store(name, value)
click to toggle source
# File lib/enver/loader.rb, line 76 def store(name, value) @attributes.send("#{name}=", value) end
with_prefix(env_name)
click to toggle source
# File lib/enver/loader.rb, line 72 def with_prefix(env_name) "#{@prefix}#{env_name}" end