class Global::Configuration
Attributes
hash[R]
Public Class Methods
new(hash)
click to toggle source
# File lib/global/configuration.rb, line 16 def initialize(hash) @hash = hash.respond_to?(:with_indifferent_access) ? hash.with_indifferent_access : hash end
Public Instance Methods
filter(options = {})
click to toggle source
# File lib/global/configuration.rb, line 20 def filter(options = {}) keys = filtered_keys_list(options) hash.select { |key, _| keys.include?(key) } end
get_configuration_value(key)
click to toggle source
# File lib/global/configuration.rb, line 25 def get_configuration_value(key) return nil unless key?(key) value = hash[key] value.is_a?(Hash) ? Global::Configuration.new(value) : value end
Protected Instance Methods
boolean_method?(method)
click to toggle source
# File lib/global/configuration.rb, line 60 def boolean_method?(method) '?' == method.to_s[-1] end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/global/configuration.rb, line 51 def method_missing(method, *args, &block) method = normalize_key_by_method(method) if key?(method) get_configuration_value(method) else super end end
normalize_key_by_method(method)
click to toggle source
# File lib/global/configuration.rb, line 64 def normalize_key_by_method(method) boolean_method?(method) ? method.to_s[0..-2].to_sym : method end
respond_to_missing?(method_name, include_private = false)
click to toggle source
Calls superclass method
# File lib/global/configuration.rb, line 46 def respond_to_missing?(method_name, include_private = false) method = normalize_key_by_method(method_name) key?(method) || boolean_method?(method) || super end
Private Instance Methods
filtered_keys_list(options)
click to toggle source
# File lib/global/configuration.rb, line 34 def filtered_keys_list(options) return hash.keys - options[:except].map(&:to_s) if options[:except].is_a?(Array) return hash.keys & options[:only].map(&:to_s) if options[:only].is_a?(Array) return hash.keys if options[:only] == :all return [] if options[:except] == :all [] end