Class: Flattery::ValueCache::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/flattery/value_cache/processor.rb

Instance Method Summary collapse

Instance Method Details

#before_save(record) ⇒ Object

Command: updates cached values for related changed attributes



4
5
6
7
8
9
10
11
# File 'lib/flattery/value_cache/processor.rb', line 4

def before_save(record)
  resolved_options!(record.class).each do |key,options|
    if record.changed & options[:changed_on]
      record.send("#{key}=", record.send(options[:from_entity]).try(:send,options[:to_entity]))
    end
  end
  true
end

#resolved_options!(klass) ⇒ Object

Command: resolves value cache options for klass if required, and returns resolved options



14
15
16
# File 'lib/flattery/value_cache/processor.rb', line 14

def resolved_options!(klass)
  klass.value_cache_options.settings
end