Class: Global::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/global/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Configuration

Returns a new instance of Configuration.



14
15
16
# File 'lib/global/configuration.rb', line 14

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)



41
42
43
44
45
46
47
48
49
# File 'lib/global/configuration.rb', line 41

def method_missing(method, *args, &block)
  method = method.to_s[0..-2] if method.to_s[-1] == '?'
  if key?(method)
    value = hash[method]
    value.kind_of?(Hash) ? Global::Configuration.new(value) : value
  else
    super
  end
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



9
10
11
# File 'lib/global/configuration.rb', line 9

def hash
  @hash
end

Instance Method Details

#filter(options = {}) ⇒ Object



18
19
20
21
# File 'lib/global/configuration.rb', line 18

def filter(options = {})
  keys = filtered_keys_list(options)
  hash.select{|key, _| keys.include?(key)}
end