Class: ActiveAny::Associations::Preloader::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/active_any/associations/preloader/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, owner_records, reflection, preload_scope) ⇒ Association

Returns a new instance of Association.



11
12
13
14
15
16
17
# File 'lib/active_any/associations/preloader/association.rb', line 11

def initialize(klass, owner_records, reflection, preload_scope)
  @klass = klass
  @owners = owner_records
  @reflection = reflection
  @preload_scope = preload_scope
  @preloaded_records = []
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



9
10
11
# File 'lib/active_any/associations/preloader/association.rb', line 9

def klass
  @klass
end

#ownersObject (readonly)

Returns the value of attribute owners.



9
10
11
# File 'lib/active_any/associations/preloader/association.rb', line 9

def owners
  @owners
end

#preload_scopeObject (readonly)

Returns the value of attribute preload_scope.



9
10
11
# File 'lib/active_any/associations/preloader/association.rb', line 9

def preload_scope
  @preload_scope
end

#preloaded_recordsObject (readonly)

Returns the value of attribute preloaded_records.



9
10
11
# File 'lib/active_any/associations/preloader/association.rb', line 9

def preloaded_records
  @preloaded_records
end

#reflectionObject (readonly)

Returns the value of attribute reflection.



9
10
11
# File 'lib/active_any/associations/preloader/association.rb', line 9

def reflection
  @reflection
end

Instance Method Details

#association_key_nameObject

The name of the key on the associated records

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/active_any/associations/preloader/association.rb', line 36

def association_key_name
  raise NotImplementedError
end

#optionsObject



44
45
46
# File 'lib/active_any/associations/preloader/association.rb', line 44

def options
  reflection.options
end

#owner_key_nameObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/active_any/associations/preloader/association.rb', line 40

def owner_key_name
  raise NotImplementedError
end

#preload(_preloader) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/active_any/associations/preloader/association.rb', line 23

def preload(_preloader)
  raise NotImplementedError
end

#records_for(ids) ⇒ Object



31
32
33
# File 'lib/active_any/associations/preloader/association.rb', line 31

def records_for(ids)
  scope.where(association_key_name => ids)
end

#run(preloader) ⇒ Object



19
20
21
# File 'lib/active_any/associations/preloader/association.rb', line 19

def run(preloader)
  preload(preloader)
end

#scopeObject



27
28
29
# File 'lib/active_any/associations/preloader/association.rb', line 27

def scope
  @scope ||= build_scope
end