Class: ActiveAny::Reflection::AssociationReflection
- Inherits:
-
Object
- Object
- ActiveAny::Reflection::AssociationReflection
show all
- Defined in:
- lib/active_any/reflection/association_reflection.rb
Defined Under Namespace
Classes: JoinKeys
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, scope, options, record_class) ⇒ AssociationReflection
Returns a new instance of AssociationReflection.
8
9
10
11
12
13
|
# File 'lib/active_any/reflection/association_reflection.rb', line 8
def initialize(name, scope, options, record_class)
@name = name
@record_class = record_class
@options = options
@scope = scope
end
|
Instance Attribute Details
Returns the value of attribute name.
6
7
8
|
# File 'lib/active_any/reflection/association_reflection.rb', line 6
def name
@name
end
|
Returns the value of attribute options.
6
7
8
|
# File 'lib/active_any/reflection/association_reflection.rb', line 6
def options
@options
end
|
#record_class ⇒ Object
Returns the value of attribute record_class.
6
7
8
|
# File 'lib/active_any/reflection/association_reflection.rb', line 6
def record_class
@record_class
end
|
Returns the value of attribute scope.
6
7
8
|
# File 'lib/active_any/reflection/association_reflection.rb', line 6
def scope
@scope
end
|
Instance Method Details
#association_class ⇒ Object
15
16
17
|
# File 'lib/active_any/reflection/association_reflection.rb', line 15
def association_class
raise NotImplementedError
end
|
#belongs_to? ⇒ Boolean
39
40
41
|
# File 'lib/active_any/reflection/association_reflection.rb', line 39
def belongs_to?
false
end
|
#check_preloadable! ⇒ Object
Also known as:
check_eager_loadable!
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/active_any/reflection/association_reflection.rb', line 57
def check_preloadable!
return unless scope
if scope.arity.positive?
raise ArgumentError, " The association scope '\#{name}' is instance dependent (the scope\n block takes an argument). Preloading instance dependent scopes is\n not supported.\n MSG\n end\nend\n".squish
|
#class_name ⇒ Object
23
24
25
|
# File 'lib/active_any/reflection/association_reflection.rb', line 23
def class_name
@class_name ||= (options[:class_name] || derive_class_name).to_s
end
|
#collection? ⇒ Boolean
35
36
37
|
# File 'lib/active_any/reflection/association_reflection.rb', line 35
def collection?
false
end
|
#compute_class(name) ⇒ Object
31
32
33
|
# File 'lib/active_any/reflection/association_reflection.rb', line 31
def compute_class(name)
name.constantize
end
|
#foreign_key ⇒ Object
49
50
51
|
# File 'lib/active_any/reflection/association_reflection.rb', line 49
def foreign_key
@foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
end
|
#inverse_of ⇒ Object
70
71
72
73
74
|
# File 'lib/active_any/reflection/association_reflection.rb', line 70
def inverse_of
return unless inverse_name
@inverse_of ||= klass._reflect_on_association inverse_name
end
|
#join_keys ⇒ Object
45
46
47
|
# File 'lib/active_any/reflection/association_reflection.rb', line 45
def join_keys
JoinKeys.new(join_pk, join_fk)
end
|
27
28
29
|
# File 'lib/active_any/reflection/association_reflection.rb', line 27
def klass
@klass ||= compute_class(class_name)
end
|
19
20
21
|
# File 'lib/active_any/reflection/association_reflection.rb', line 19
def marco
raise NotImplementedError
end
|
#record_class_primary_key ⇒ Object
76
77
78
|
# File 'lib/active_any/reflection/association_reflection.rb', line 76
def record_class_primary_key
@primary_key ||= options[:primary_key] || primary_key(record_class)
end
|
#scope_for(klass) ⇒ Object
53
54
55
|
# File 'lib/active_any/reflection/association_reflection.rb', line 53
def scope_for(klass)
scope ? klass.unscoped.instance_exec(nil, &scope) : klass.unscoped
end
|