Class: DelegateCached::CachedAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/delegate_cached/cached_attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute, reflection, options) ⇒ CachedAttribute

Returns a new instance of CachedAttribute.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/delegate_cached/cached_attribute.rb', line 10

def initialize(model, attribute, reflection, options)
  @options = options
  @source = source_model_data(model, attribute, reflection, options)

  inverse = nil
  if reflection.polymorphic?
    @options[:polymorphic] = true
  else
    inverse = reflection.inverse_of
    inverse ||= retrieve_reflection(options[:inverse_of])
    @options[:skip_callback] = true if inverse.nil?
  end

  @target = target_model_data(attribute, reflection, inverse)

  @source_installer = SourceInstaller.new(@source, @target, options)
  @target_installer = TargetInstaller.new(@source, @target, options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/delegate_cached/cached_attribute.rb', line 8

def options
  @options
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/delegate_cached/cached_attribute.rb', line 8

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/delegate_cached/cached_attribute.rb', line 8

def target
  @target
end

Instance Method Details

#install!Object



29
30
31
32
33
# File 'lib/delegate_cached/cached_attribute.rb', line 29

def install!
  validate
  @source_installer.install_instance_methods
  @target_installer.install_instance_methods
end