Class: ModSpox::Models::Setting
- Inherits:
-
Object
- Object
- ModSpox::Models::Setting
- 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
Class Method Summary collapse
-
.[](key) ⇒ Object
- key
-
name of the setting Returns the setting with the given name.
-
.[]=(key, val) ⇒ Object
- key
- name of the setting val
-
value of the setting Stores the val in setting named by the given key Note: Will fail if attempting to save hashes.
Instance Method Summary collapse
Class Method Details
.[](key) ⇒ Object
- key
-
name of the setting
Returns the setting with the given name
23 24 25 26 27 |
# File 'lib/mod_spox/models/Setting.rb', line 23 def self.[](key) key = key.to_s if key.is_a?(Symbol) setting = Setting.filter(:name => key).first return setting ? setting.value : nil end |
.[]=(key, val) ⇒ Object
- key
-
name of the setting
- val
-
value of the setting
Stores the val in setting named by the given key Note: Will fail if attempting to save hashes. Must set value explicitly
33 34 35 36 37 |
# File 'lib/mod_spox/models/Setting.rb', line 33 def self.[]=(key, val) key = key.to_s if key.is_a?(Symbol) model = Setting.find_or_create(:name => key) model.update_with_params(:value => Base64.encode64(Marshal.dump(val))) end |
Instance Method Details
#value ⇒ Object
17 18 19 |
# File 'lib/mod_spox/models/Setting.rb', line 17 def value return values[:value] ? Marshal.load(Base64.decode64(values[:value])) : nil end |
#value=(val) ⇒ Object
13 14 15 |
# File 'lib/mod_spox/models/Setting.rb', line 13 def value=(val) update_values(:value => Base64.encode64(Marshal.dump(val))) end |