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.
7
8
9
10
11
12
|
# File 'lib/identity_cache/cached/association.rb', line 7
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.
14
15
16
|
# File 'lib/identity_cache/cached/association.rb', line 14
def cached_accessor_name
@cached_accessor_name
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/identity_cache/cached/association.rb', line 14
def name
@name
end
|
#records_variable_name ⇒ Object
Returns the value of attribute records_variable_name.
14
15
16
|
# File 'lib/identity_cache/cached/association.rb', line 14
def records_variable_name
@records_variable_name
end
|
#reflection ⇒ Object
Returns the value of attribute reflection.
14
15
16
|
# File 'lib/identity_cache/cached/association.rb', line 14
def reflection
@reflection
end
|
Instance Method Details
#build ⇒ Object
16
17
18
|
# File 'lib/identity_cache/cached/association.rb', line 16
def build
raise NotImplementedError
end
|
#clear(_record) ⇒ Object
28
29
30
|
# File 'lib/identity_cache/cached/association.rb', line 28
def clear(_record)
raise NotImplementedError
end
|
#embedded? ⇒ Boolean
40
41
42
|
# File 'lib/identity_cache/cached/association.rb', line 40
def embedded?
embedded_by_reference? || embedded_recursively?
end
|
#embedded_by_reference? ⇒ Boolean
44
45
46
|
# File 'lib/identity_cache/cached/association.rb', line 44
def embedded_by_reference?
raise NotImplementedError
end
|
#embedded_recursively? ⇒ Boolean
48
49
50
|
# File 'lib/identity_cache/cached/association.rb', line 48
def embedded_recursively?
raise NotImplementedError
end
|
#fetch(_records) ⇒ Object
32
33
34
|
# File 'lib/identity_cache/cached/association.rb', line 32
def fetch(_records)
raise NotImplementedError
end
|
#fetch_async(_load_strategy, _records) ⇒ Object
36
37
38
|
# File 'lib/identity_cache/cached/association.rb', line 36
def fetch_async(_load_strategy, _records)
raise NotImplementedError
end
|
#inverse_name ⇒ Object
52
53
54
55
56
57
|
# File 'lib/identity_cache/cached/association.rb', line 52
def inverse_name
@inverse_name ||= begin
reflection.inverse_of&.name ||
reflection.active_record.name.underscore
end
end
|
#read(_record) ⇒ Object
20
21
22
|
# File 'lib/identity_cache/cached/association.rb', line 20
def read(_record)
raise NotImplementedError
end
|
#validate ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/identity_cache/cached/association.rb', line 59
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
24
25
26
|
# File 'lib/identity_cache/cached/association.rb', line 24
def write(_record, _value)
raise NotImplementedError
end
|