Class: Sequelinha::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.



3
4
5
# File 'lib/sequelinha/config.rb', line 3

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/sequelinha/config.rb', line 19

def method_missing(sym, *args)
  if sym.to_s =~ /(.+)=$/
    self[$1] = args.first
  else
    self[sym]
  end
end

Instance Method Details

#[](key) ⇒ Object



7
8
9
# File 'lib/sequelinha/config.rb', line 7

def [](key)
  @data[key.to_sym]
end

#[]=(key, value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/sequelinha/config.rb', line 11

def []=(key, value)
  if value.class == Hash
    @data[key.to_sym] = Config.new(value)
  else
    @data[key.to_sym] = value
  end
end