Module: SettingAccessors::SettingScaffold
- Defined in:
- lib/setting_accessors/setting_scaffold.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#default_value ⇒ Object
The default value for the current setting.
-
#raw_value ⇒ Object
We can’t use the name #value_before_type_cast here as it would shadow ActiveRecord’s default one - which might still be needed.
-
#raw_value=(new_value) ⇒ Object
Sets the new setting value by converting the raw value automatically.
-
#value_type ⇒ String
The setting’s type as specified in settings.yml If the setting wasn’t specified, a polymorphic type is assumed.
Class Method Details
.included(base) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 12 def self.included(base) base.extend ClassMethods base.serialize :value base.validates :name, uniqueness: {scope: [:assignable_type, :assignable_id]}, presence: true end |
Instance Method Details
#default_value ⇒ Object
Returns the default value for the current setting.
141 142 143 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 141 def default_value data['default'].freeze end |
#raw_value ⇒ Object
We can’t use the name #value_before_type_cast here as it would shadow ActiveRecord’s default one - which might still be needed.
160 161 162 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 160 def raw_value @raw_value || value end |
#raw_value=(new_value) ⇒ Object
Sets the new setting value by converting the raw value automatically.
167 168 169 170 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 167 def raw_value=(new_value) @raw_value = new_value self.value = converter.new(new_value).convert end |
#value_type ⇒ String
Returns the setting’s type as specified in settings.yml If the setting wasn’t specified, a polymorphic type is assumed.
149 150 151 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 149 def value_type data['type'] || 'polymorphic' end |