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 the setting_accessor call.
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.
153 154 155 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 153 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.
172 173 174 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 172 def raw_value @raw_value || value end |
#raw_value=(new_value) ⇒ Object
Sets the new setting value by converting the raw value automatically.
179 180 181 182 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 179 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 the setting_accessor call. If no type was specified, a polymorphic type is assumed.
161 162 163 |
# File 'lib/setting_accessors/setting_scaffold.rb', line 161 def value_type data['type'] || 'polymorphic' end |