Class: Gitlab::Reflections::Relationships::Handlers::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/reflections/relationships/handlers/base_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#modelObject (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

#reflectionObject (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_relationshipsObject



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_attributesObject



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