Module: Flattery::ValueCache::ClassMethods

Defined in:
lib/flattery/value_cache.rb

Instance Method Summary collapse

Instance Method Details

#flatten_value(options = {}) ⇒ Object

Command: adds flattery definition options. The options define a single cache setting. To define multiple cache settings, call flatten_value once for each setting.

options by example:

flatten_value :category => :name
# => will cache self.category.name to self.category_name
flatten_value :category => :name, :as => 'cat_name'
# => will cache self.category.name to self.cat_name

When explicitly passed nil, it clears all existing settings



21
22
23
# File 'lib/flattery/value_cache.rb', line 21

def flatten_value(options={})
  self.value_cache_options.add_setting(options)
end

#value_cache_optionsObject

Returns the Flattery::ValueCache options value object. It will inherit settings from a parent class if a model hierarchy has been defined



27
28
29
30
31
32
33
34
35
# File 'lib/flattery/value_cache.rb', line 27

def value_cache_options
  @value_cache_options ||= if superclass.respond_to?(:value_cache_options)
    my_settings = Settings.new(self)
    my_settings.raw_settings = superclass.value_cache_options.raw_settings.dup
    my_settings
  else
    Settings.new(self)
  end
end