Class: DummyAccess

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

Overview

Class to ease the getting and setting of configuration values

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ DummyAccess

Returns a new instance of DummyAccess.



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

def initialize(mod)
  @mod = mod
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dummy_access.rb', line 7

def method_missing(method_name, *args)
  method_name = method_name.to_s
  name = method_name.chomp '='
  conf = @mod.configs.find_by_name name
  
  if method_name.ends_with? '='
    conf ? conf.update_attribute(:value, args[0]) : @mod.configs.create!(:name => name, :value => args[0])
    conf
  else
    conf ? conf.value : raise("Configuration attribute '#{method_name}' doesn't exists")
  end
end