class Msg91ruby::Options
Public Instance Methods
[](param)
click to toggle source
An alternative mechanism for property access. This let's you do foo along with foo.bar.
# File lib/msg91ruby/options.rb, line 90 def [](param) send("#{param}") end
[]=(param, value)
click to toggle source
# File lib/msg91ruby/options.rb, line 94 def []=(param, value) send("#{param}=", value) end
add_source!(source)
click to toggle source
# File lib/msg91ruby/options.rb, line 11 def add_source!(source) # handle yaml file paths source = (Sources::YAMLSource.new(source)) if source.is_a?(String) @config_sources ||= [] @config_sources << source end
each(*args, &block)
click to toggle source
# File lib/msg91ruby/options.rb, line 72 def each(*args, &block) marshal_dump.each(*args, &block) end
empty?()
click to toggle source
# File lib/msg91ruby/options.rb, line 7 def empty? marshal_dump.empty? end
merge!(hash)
click to toggle source
# File lib/msg91ruby/options.rb, line 81 def merge!(hash) current = to_hash DeepMerge.deep_merge!(hash.dup, current) marshal_load(__convert(current).marshal_dump) self end
reload!()
click to toggle source
look through all our sources and rebuild the configuration
# File lib/msg91ruby/options.rb, line 37 def reload! conf = {} @config_sources.each do |source| source_conf = source.load if conf.empty? conf = source_conf else DeepMerge.deep_merge!(source_conf, conf, :preserve_unmergeables => false) end end # swap out the contents of the OStruct with a hash (need to recursively convert) marshal_load(__convert(conf).marshal_dump) reload_env! if Msg91ruby.use_env return self end
Also aliased as: load!
reload_env!()
click to toggle source
# File lib/msg91ruby/options.rb, line 19 def reload_env! return self if ENV.nil? || ENV.empty? conf = Hash.new ENV.each do |key, value| next unless key.to_s.index(Msg91ruby.const_name) == 0 hash = value key.to_s.split('.').reverse.each do |element| hash = {element => hash} end DeepMerge.deep_merge!(hash, conf, :preserve_unmergeables => false) end merge!(conf[Msg91ruby.const_name] || {}) end
Also aliased as: load_env!
reload_from_files(*files)
click to toggle source
# File lib/msg91ruby/options.rb, line 59 def reload_from_files(*files) Msg91ruby.load_and_set_settings(files) reload! end
to_hash()
click to toggle source
# File lib/msg91ruby/options.rb, line 64 def to_hash result = {} marshal_dump.each do |k, v| result[k] = v.instance_of?(Msg91ruby::Options) ? v.to_hash : v end result end
to_json(*args)
click to toggle source
# File lib/msg91ruby/options.rb, line 76 def to_json(*args) require "json" unless defined?(JSON) to_hash.to_json(*args) end