Class: Tunable::Setting

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
ActiveRecordExtensions
Defined in:
lib/tunable/setting.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecordExtensions

import

Class Method Details

.store_many(hash, object) ⇒ Object

this method regenerates all settings when updating a device. we first remove all the settings (we dont get params from disabled modules)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tunable/setting.rb', line 24

def self.store_many(hash, object)
  wipe_all(object) and return if hash.blank?

  hash.each do |context, fields|
    fields.each do |key, val|
      if val.blank? && !object.settings_context(context.to_sym)[key.to_sym].nil?

        # setting was present and now deleted
        object.queue_setting_for_deletion(context, key)

      elsif val != object.settings_context(context.to_sym)[key.to_sym]

        # settings different from previous, so update
        object.queue_setting_for_update(context, key, val)
      end
    end
  end
end

.wipe_all(object) ⇒ Object



43
44
45
46
47
# File 'lib/tunable/setting.rb', line 43

def self.wipe_all(object)
  count = object.settings.where("`context` != 'main'").delete_all
  # debug "#{count} deleted settings."
  true
end

Instance Method Details

#normalized_valueObject



49
50
51
# File 'lib/tunable/setting.rb', line 49

def normalized_value
  Tunable.normalize_and_get(self[:value])
end

#value=(val) ⇒ Object



53
54
55
# File 'lib/tunable/setting.rb', line 53

def value=(val)
  self[:value] = Tunable.normalize_value(val)
end