Class: KVC::SettingsProxy
- Inherits:
-
Object
- Object
- KVC::SettingsProxy
- Defined in:
- lib/kvc/settings_proxy.rb
Overview
The KVC::SettingsProxy proxies to a KVC::Settings object’s value. The proxy ensures that when a value is modified, the Settings object is immediately updated in the database.
These proxies also provide access to the Settings object’s timestamp attributes.
Instance Attribute Summary collapse
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
Instance Method Summary collapse
-
#initialize(setting) ⇒ SettingsProxy
constructor
A new instance of SettingsProxy.
Constructor Details
#initialize(setting) ⇒ SettingsProxy
Returns a new instance of SettingsProxy.
12 13 14 |
# File 'lib/kvc/settings_proxy.rb', line 12 def initialize(setting) @setting = setting end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kvc/settings_proxy.rb', line 18 def method_missing(method, *args, &block) return setting.send(method) if [:created_at, :updated_at].include? method return_value = setting.value.send(method, *args, &block) stored_value = KVC::Settings.deserialize YAML.load(setting[:value]) if setting.value != stored_value setting.update_attribute :value, setting.value return self # Allow for chaining. end return_value end |
Instance Attribute Details
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
10 11 12 |
# File 'lib/kvc/settings_proxy.rb', line 10 def setting @setting end |