Class: Mona::Config

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

Defined Under Namespace

Classes: Loader, Manager

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Config

Returns a new instance of Config.



2
3
4
# File 'lib/mona/config.rb', line 2

def initialize(attributes = {})
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args) ⇒ Object



14
15
16
# File 'lib/mona/config.rb', line 14

def method_missing(method_name, *_args)
  read_attribute(method_name)
end

Instance Method Details

#read_attribute(key) ⇒ Object



6
7
8
# File 'lib/mona/config.rb', line 6

def read_attribute(key)
  @attributes[key.to_s]
end

#to_hObject



18
19
20
21
22
# File 'lib/mona/config.rb', line 18

def to_h
  @attributes.each_with_object({}) do |(k, v), h|
    h[k] = self.class === v ? v.to_h : v
  end
end

#write_attribute(key, value) ⇒ Object



10
11
12
# File 'lib/mona/config.rb', line 10

def write_attribute(key, value)
  @attributes[key.to_s] = value
end