Class: HasConfig::ActiveRecord::Processor
- Inherits:
-
Object
- Object
- HasConfig::ActiveRecord::Processor
- Defined in:
- lib/has_config/active_record/processor.rb
Instance Method Summary collapse
- #fetch(configuration, parent: nil, mode: :none) ⇒ Object
-
#initialize(model) ⇒ Processor
constructor
A new instance of Processor.
- #set(configuration, value) ⇒ Object
Constructor Details
#initialize(model) ⇒ Processor
Returns a new instance of Processor.
4 5 6 |
# File 'lib/has_config/active_record/processor.rb', line 4 def initialize(model) @model = model end |
Instance Method Details
#fetch(configuration, parent: nil, mode: :none) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/has_config/active_record/processor.rb', line 8 def fetch(configuration, parent: nil, mode: :none) local = local_value(has_config_column_data, configuration) if parent && mode == :resolve && HasConfig::Chain.invoke?(local, configuration.chain_on) check_chain(configuration, parent) parent_value = @model.public_send(parent).public_send(configuration.name, :resolve) return parent_value unless parent_value.blank? end local end |
#set(configuration, value) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/has_config/active_record/processor.rb', line 20 def set(configuration, value) data = has_config_column_data parsed_value = HasConfig::ValueParser.parse(value, configuration.type) if data[configuration.name] != parsed_value data[configuration.name] = parsed_value @model.send(:write_attribute, has_config_column, data) @model.public_send("#{has_config_column}_will_change!") end end |