Class: Gitlab::Reflections::Relationships::Handlers::BaseHandler
- Inherits:
-
Object
- Object
- Gitlab::Reflections::Relationships::Handlers::BaseHandler
- Defined in:
- lib/gitlab/reflections/relationships/handlers/base_handler.rb
Direct Known Subclasses
ActiveStorageHandler, BelongsToHandler, HabtmHandler, HasAssociationHandler, PolymorphicBelongsToHandler, PolymorphicHasAssociationHandler, ThroughAssociationHandler
Instance Attribute Summary collapse
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
- #build_relationships ⇒ Object
-
#initialize(model, association_name, reflection) ⇒ BaseHandler
constructor
A new instance of BaseHandler.
- #relationship_attributes ⇒ Object
Constructor Details
#initialize(model, association_name, reflection) ⇒ BaseHandler
Returns a new instance of BaseHandler.
8 9 10 11 12 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 8 def initialize(model, association_name, reflection) @model = model @association_name = association_name @reflection = reflection end |
Instance Attribute Details
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
23 24 25 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 23 def association_name @association_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
23 24 25 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 23 def model @model end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
23 24 25 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 23 def reflection @reflection end |
Instance Method Details
#build_relationships ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 14 def build_relationships relationship = build_relationship(**relationship_attributes) relationship ? [relationship] : [] rescue NameError # Skip associations where the target class doesn't exist # This can happen when models reference classes that have been removed [] end |
#relationship_attributes ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/gitlab/reflections/relationships/handlers/base_handler.rb', line 25 def relationship_attributes { parent_table: model.table_name, child_table: reflection.klass.table_name, relationship_type: relationship_type } end |