Module: Tunable::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/tunable/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #clear_instance_settings ⇒ Object
- #get_main_setting(key) ⇒ Object
- #get_setting(context, key) ⇒ Object
- #main_settings ⇒ Object
- #queue_setting_for_deletion(context, key) ⇒ Object
- #queue_setting_for_update(context, key, val) ⇒ Object
- #setting_off?(context, key) ⇒ Boolean
- #setting_on?(context, key) ⇒ Boolean
-
#settings=(hash) ⇒ Object
instance methods below.
- #settings_context(context) ⇒ Object
- #settings_hash ⇒ Object
Instance Method Details
#clear_instance_settings ⇒ Object
175 176 177 178 |
# File 'lib/tunable/model.rb', line 175 def clear_instance_settings @object_hashed_settings = nil @settings = nil # so settings get reloaded from DB end |
#get_main_setting(key) ⇒ Object
163 164 165 |
# File 'lib/tunable/model.rb', line 163 def get_main_setting(key) get_setting(:main, key) end |
#get_setting(context, key) ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/tunable/model.rb', line 154 def get_setting(context, key) val = settings_context(context)[key] # if value is nil or no default is set, stop here return val if !val.nil? or self.class.default_settings(context)[key.to_sym].nil? self.class.default_settings(context)[key.to_sym] end |
#main_settings ⇒ Object
171 172 173 |
# File 'lib/tunable/model.rb', line 171 def main_settings settings_context(:main) end |
#queue_setting_for_deletion(context, key) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/tunable/model.rb', line 195 def queue_setting_for_deletion(context, key) if self.class.main_settings_list.include?(key) send('changed_attributes')[key.to_sym] = nil end (deleted_settings[context.to_sym] ||= []) << key.to_sym end |
#queue_setting_for_update(context, key, val) ⇒ Object
188 189 190 191 192 193 |
# File 'lib/tunable/model.rb', line 188 def queue_setting_for_update(context, key, val) if self.class.main_settings_list.include?(key.to_sym) send('changed_attributes')[key.to_sym] = val end (modified_settings[context.to_sym] ||= {})[key.to_sym] = val end |
#setting_off?(context, key) ⇒ Boolean
180 181 182 |
# File 'lib/tunable/model.rb', line 180 def setting_off?(context, key) get_setting(context, key) == false end |
#setting_on?(context, key) ⇒ Boolean
184 185 186 |
# File 'lib/tunable/model.rb', line 184 def setting_on?(context, key) get_setting(context, key) == true end |
#settings=(hash) ⇒ Object
instance methods below
141 142 143 144 |
# File 'lib/tunable/model.rb', line 141 def settings=(hash) puts hash.inspect Tunable::Setting.store_many(hash, self) end |
#settings_context(context) ⇒ Object
167 168 169 |
# File 'lib/tunable/model.rb', line 167 def settings_context(context) settings_hash[context.to_sym] || {} end |