Class: Cardboard::Setting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cardboard/setting.rb

Class Method Summary collapse

Class Method Details

.add(id, hash_attributes) ⇒ Object



19
20
21
22
23
# File 'app/models/cardboard/setting.rb', line 19

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_settingsObject



25
26
27
28
29
# File 'app/models/cardboard/setting.rb', line 25

def clear_saved_settings
  @lock.synchronize do
    @_settings = nil
  end
end

.method_missing(sym, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/cardboard/setting.rb', line 31

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