Class: ModSpox::Models::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mod_spox/models/Config.rb

Overview

Attributes provided by model:

name

name of the config item

value

value of the config item

It is important to note this model is for storing configuration values only. It will only store strings, not complex objects. If you need to store an object, use the Setting model.

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

key

name of the config item

Returns the value of config item named the given key



14
15
16
17
18
# File 'lib/mod_spox/models/Config.rb', line 14

def self.[](key)
    key = key.to_s if key.is_a?(Symbol)
    match = Config.filter(:name => key).first
    return match ? match.value : nil
end

.[]=(key, val) ⇒ Object

key

name of the config item

val

value of the config item

Modifies or creates config item and stores the value



23
24
25
26
27
28
# File 'lib/mod_spox/models/Config.rb', line 23

def self.[]=(key, val)
    key = key.to_s if key.is_a?(Symbol)
    model = Config.find_or_create(:name => key)
    model.value = val
    model.save
end