Class: ActiveGraph::Node::Reflection::AssociationReflection
- Inherits:
-
Object
- Object
- ActiveGraph::Node::Reflection::AssociationReflection
- Defined in:
- lib/active_graph/node/reflection.rb
Overview
The actual reflection object that contains information about the given association. These should never need to be created manually, they will always be created by declaring a :has_many or :has_one association on a model.
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
The association object referenced by this reflection.
-
#macro ⇒ Object
readonly
The type of association.
-
#name ⇒ Object
readonly
The name of the association.
Instance Method Summary collapse
-
#class_name ⇒ Object
Returns the name of the target model.
- #collection? ⇒ Boolean
-
#initialize(macro, name, association) ⇒ AssociationReflection
constructor
A new instance of AssociationReflection.
-
#klass ⇒ Object
Returns the target model.
- #rel_class_name ⇒ Object
- #rel_klass ⇒ Object
- #type ⇒ Object
- #validate? ⇒ Boolean
Constructor Details
#initialize(macro, name, association) ⇒ AssociationReflection
Returns a new instance of AssociationReflection.
49 50 51 52 53 |
# File 'lib/active_graph/node/reflection.rb', line 49 def initialize(macro, name, association) @macro = macro @name = name @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
The association object referenced by this reflection
47 48 49 |
# File 'lib/active_graph/node/reflection.rb', line 47 def association @association end |
#macro ⇒ Object (readonly)
The type of association
44 45 46 |
# File 'lib/active_graph/node/reflection.rb', line 44 def macro @macro end |
#name ⇒ Object (readonly)
The name of the association
41 42 43 |
# File 'lib/active_graph/node/reflection.rb', line 41 def name @name end |
Instance Method Details
#class_name ⇒ Object
Returns the name of the target model
61 62 63 |
# File 'lib/active_graph/node/reflection.rb', line 61 def class_name @class_name ||= association.target_class.name end |
#collection? ⇒ Boolean
77 78 79 |
# File 'lib/active_graph/node/reflection.rb', line 77 def collection? macro == :has_many end |
#klass ⇒ Object
Returns the target model
56 57 58 |
# File 'lib/active_graph/node/reflection.rb', line 56 def klass @klass ||= class_name.constantize end |
#rel_class_name ⇒ Object
69 70 71 |
# File 'lib/active_graph/node/reflection.rb', line 69 def rel_class_name @rel_class_name ||= association.relationship_class.name.to_s end |
#rel_klass ⇒ Object
65 66 67 |
# File 'lib/active_graph/node/reflection.rb', line 65 def rel_klass @rel_klass ||= rel_class_name.constantize end |
#type ⇒ Object
73 74 75 |
# File 'lib/active_graph/node/reflection.rb', line 73 def type @type ||= association.relationship_type end |
#validate? ⇒ Boolean
81 82 83 |
# File 'lib/active_graph/node/reflection.rb', line 81 def validate? true end |