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

rubocop:enable Lint/BooleanSymbol



31
32
33
# File 'lib/global/configuration.rb', line 31

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)



66
67
68
69
70
71
72
73
74
# File 'lib/global/configuration.rb', line 66

def method_missing(method, *args, &block)
  normalized_method = normalize_key_by_method(method)
  if key?(normalized_method)
    value = get_configuration_value(normalized_method)
    boolean_method?(method) ? cast_boolean(value) : value
  else
    super
  end
end

Instance Attribute Details

#hashObject (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



35
36
37
38
# File 'lib/global/configuration.rb', line 35

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

#get_configuration_value(key) ⇒ Object



40
41
42
43
44
45
# File 'lib/global/configuration.rb', line 40

def get_configuration_value(key)
  return nil unless key?(key)

  value = hash[key]
  value.is_a?(Hash) ? Global::Configuration.new(value) : value
end