Class: UniqSysOmega::Tariffs::Settings::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Proxy

Returns a new instance of Proxy.

Raises:

  • (ArgumentError)


19
20
21
22
# File 'lib/settings.rb', line 19

def initialize(hash)
  raise ArgumentError, "Invalid argument for settings. Should be hash." unless hash.kind_of?(Hash)
  @hash = HashWithIndifferentAccess.new(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



24
25
26
27
28
# File 'lib/settings.rb', line 24

def method_missing(meth, *args)
  entry = @hash[meth]
  return Proxy.new(entry) if entry.kind_of?(Hash)
  entry
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
# File 'lib/settings.rb', line 34

def ==(other)
  raise "Invalid comparison" unless other.kind_of?(Hash) || other.kind_of?(Settings::Proxy) || other.kind_of?(Settings)
  @hash == HashWithIndifferentAccess.new(other.to_hash)
end

#to_hashObject



30
31
32
# File 'lib/settings.rb', line 30

def to_hash
  @hash.dup
end