Class: ModSpox::Models::Setting

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/mod_spox/models/Setting.rb

Overview

Attributes provided by model:

name

name of the setting

value

value of the setting

This model can be used to store complex objects. These objects are dumped and stored for later retrieval TODO: remove [] from any usage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.set(sym, value) ⇒ Object



28
29
30
31
32
# File 'lib/mod_spox/models/Setting.rb', line 28

def Setting.set(sym, value)
    s = Setting.find_or_create(:name => "#{sym}")
    s.value = value
    s.save
end

.val(sym) ⇒ Object



34
35
36
37
# File 'lib/mod_spox/models/Setting.rb', line 34

def Setting.val(sym)
    s = Setting.filter(:name => "#{sym}").first
    return s ? s.value : nil
end

Instance Method Details

#name=(setting_name) ⇒ Object

serialize(:value, :format => :marshal)



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

def name=(setting_name)
    setting_name.downcase!
    super(setting_name)
end

#valueObject



24
25
26
# File 'lib/mod_spox/models/Setting.rb', line 24

def value
    return values[:value] ? Marshal.load(values[:value].unpack('m')[0]) : nil
end

#value=(val) ⇒ Object



19
20
21
22
# File 'lib/mod_spox/models/Setting.rb', line 19

def value=(val)
    val = [Marshal.dump(val.dup)].pack('m')
    super(val)
end