Class: Global::Configuration
- Inherits:
-
Object
- Object
- Global::Configuration
- Extended by:
- Forwardable
- Defined in:
- lib/global/configuration.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #filter(options = {}) ⇒ Object
- #get_configuration_value(key) ⇒ Object
-
#initialize(hash) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(hash) ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 |
# File 'lib/global/configuration.rb', line 16 def initialize(hash) @hash = hash.respond_to?(:with_indifferent_access) ? hash.with_indifferent_access : hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
51 52 53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
10 11 12 |
# File 'lib/global/configuration.rb', line 10 def hash @hash end |
Instance Method Details
#filter(options = {}) ⇒ Object
20 21 22 23 |
# File 'lib/global/configuration.rb', line 20 def filter( = {}) keys = filtered_keys_list() hash.select { |key, _| keys.include?(key) } end |
#get_configuration_value(key) ⇒ Object
25 26 27 28 29 30 |
# 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 |