Class: IdentityCache::Cached::Association
- Inherits:
-
Object
- Object
- IdentityCache::Cached::Association
show all
- Includes:
- EmbeddedFetching
- Defined in:
- lib/identity_cache/cached/association.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, reflection:) ⇒ Association
Returns a new instance of Association.
8
9
10
11
12
13
|
# File 'lib/identity_cache/cached/association.rb', line 8
def initialize(name, reflection:)
@name = name
@reflection = reflection
@cached_accessor_name = :"fetch_#{name}"
@records_variable_name = :"@cached_#{name}"
end
|
Instance Attribute Details
#cached_accessor_name ⇒ Object
Returns the value of attribute cached_accessor_name.
15
16
17
|
# File 'lib/identity_cache/cached/association.rb', line 15
def cached_accessor_name
@cached_accessor_name
end
|
#name ⇒ Object
Returns the value of attribute name.
15
16
17
|
# File 'lib/identity_cache/cached/association.rb', line 15
def name
@name
end
|
#records_variable_name ⇒ Object
Returns the value of attribute records_variable_name.
15
16
17
|
# File 'lib/identity_cache/cached/association.rb', line 15
def records_variable_name
@records_variable_name
end
|
#reflection ⇒ Object
Returns the value of attribute reflection.
15
16
17
|
# File 'lib/identity_cache/cached/association.rb', line 15
def reflection
@reflection
end
|
Instance Method Details
#build ⇒ Object
17
18
19
|
# File 'lib/identity_cache/cached/association.rb', line 17
def build
raise NotImplementedError
end
|
#clear(_record) ⇒ Object
29
30
31
|
# File 'lib/identity_cache/cached/association.rb', line 29
def clear(_record)
raise NotImplementedError
end
|
#embedded? ⇒ Boolean
41
42
43
|
# File 'lib/identity_cache/cached/association.rb', line 41
def embedded?
embedded_by_reference? || embedded_recursively?
end
|
#embedded_by_reference? ⇒ Boolean
45
46
47
|
# File 'lib/identity_cache/cached/association.rb', line 45
def embedded_by_reference?
raise NotImplementedError
end
|
#embedded_recursively? ⇒ Boolean
49
50
51
|
# File 'lib/identity_cache/cached/association.rb', line 49
def embedded_recursively?
raise NotImplementedError
end
|
#fetch(_records) ⇒ Object
33
34
35
|
# File 'lib/identity_cache/cached/association.rb', line 33
def fetch(_records)
raise NotImplementedError
end
|
#fetch_async(_load_strategy, _records) ⇒ Object
37
38
39
|
# File 'lib/identity_cache/cached/association.rb', line 37
def fetch_async(_load_strategy, _records)
raise NotImplementedError
end
|
#inverse_name ⇒ Object
53
54
55
|
# File 'lib/identity_cache/cached/association.rb', line 53
def inverse_name
@inverse_name ||= reflection.inverse_of&.name || reflection.active_record.name.underscore
end
|
#read(_record) ⇒ Object
21
22
23
|
# File 'lib/identity_cache/cached/association.rb', line 21
def read(_record)
raise NotImplementedError
end
|
#validate ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/identity_cache/cached/association.rb', line 57
def validate
parent_class = reflection.active_record
child_class = reflection.klass
unless child_class < IdentityCache::WithoutPrimaryIndex
if embedded_recursively?
raise UnsupportedAssociationError, <<~MSG.squish
cached association #{parent_class}\##{reflection.name} requires
associated class #{child_class} to include IdentityCache
or IdentityCache::WithoutPrimaryIndex
MSG
else
raise UnsupportedAssociationError, <<~MSG.squish
cached association #{parent_class}\##{reflection.name} requires
associated class #{child_class} to include IdentityCache
MSG
end
end
unless child_class.reflect_on_association(inverse_name)
raise InverseAssociationError, <<~MSG
Inverse name for association #{parent_class}\##{reflection.name} could not be determined.
Use the :inverse_of option on the Active Record association to specify the inverse association name.
MSG
end
end
|
#write(_record, _value) ⇒ Object
25
26
27
|
# File 'lib/identity_cache/cached/association.rb', line 25
def write(_record, _value)
raise NotImplementedError
end
|