Class: Cardboard::Setting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cardboard::Setting
- Defined in:
- app/models/cardboard/setting.rb
Class Method Summary collapse
- .add(id, hash_attributes) ⇒ Object
- .clear_saved_settings ⇒ Object
- .method_missing(sym, *args, &block) ⇒ Object
Class Method Details
.add(id, hash_attributes) ⇒ Object
17 18 19 20 21 |
# File 'app/models/cardboard/setting.rb', line 17 def add(id, hash_attributes) myself = self.first_or_create field = myself.fields.where(identifier: id).first_or_initialize field.update_attributes!(hash_attributes) end |
.clear_saved_settings ⇒ Object
23 24 25 26 27 |
# File 'app/models/cardboard/setting.rb', line 23 def clear_saved_settings @lock.synchronize do @_settings = nil end end |
.method_missing(sym, *args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/cardboard/setting.rb', line 29 def method_missing(sym, *args, &block) begin super rescue @lock.synchronize do @_settings ||= {} @_settings[sym.to_sym] ||= begin return nil unless self.first s = self.first.fields.where(identifier: sym.to_s).first raise ::ActiveRecord::NoMethodError if s.nil? s.value end end end end |