Module: DelegateCached::ClassMethods

Defined in:
lib/delegate_cached.rb

Instance Method Summary collapse

Instance Method Details

#delegate_cached(attribute, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/delegate_cached.rb', line 11

def delegate_cached(attribute, options = {})
  raise ArgumentError, 'The :to option is required' unless options[:to]

  reflection = reflect_on_association(options[:to])

  if reflection.blank?
    raise ArgumentError,
          "The :to association :#{options[:to]} must exist on #{self}"
  end

  CachedAttribute.new(self, attribute, reflection, options).install!
end