Module: Golden::Setting::Value::ClassMethods
- Defined in:
- lib/golden/setting/value.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #first_or_new_object(name) ⇒ Object
- #is_true?(name) ⇒ Boolean
- #new_object(name) ⇒ Object
- #object(name) ⇒ Object
- #save_default(name, value) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
26 27 28 29 |
# File 'lib/golden/setting/value.rb', line 26 def [] name record = object(name) record ? record.value : defaults[name.to_sym] end |
#[]=(name, value) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/golden/setting/value.rb', line 31 def []= name, value record = first_or_new_object(name) if record.value != value record.value = value record.save! end value end |
#first_or_new_object(name) ⇒ Object
21 22 23 24 |
# File 'lib/golden/setting/value.rb', line 21 def first_or_new_object name raise Error::SettingNoMethod, :first_or_new_object unless defined? super super name end |
#is_true?(name) ⇒ Boolean
40 41 42 43 |
# File 'lib/golden/setting/value.rb', line 40 def is_true? name raise Error::SettingNoMethod, :is_true? unless defined? super super end |
#new_object(name) ⇒ Object
16 17 18 19 |
# File 'lib/golden/setting/value.rb', line 16 def new_object name raise Error::SettingNoMethod, :new_object unless defined? super super name end |
#object(name) ⇒ Object
11 12 13 14 |
# File 'lib/golden/setting/value.rb', line 11 def object name raise Error::SettingNoMethod, :object unless defined? super super name end |
#save_default(name, value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/golden/setting/value.rb', line 45 def save_default name, value return unless self[name].nil? record = first_or_new_object(name) if record.value != value record.group ||= Golden::Setting.default_group record.value = value record.save! end value end |