Class: PruneAr::BelongsToAssociation
- Inherits:
-
Object
- Object
- PruneAr::BelongsToAssociation
- Defined in:
- lib/prune_ar/belongs_to_association.rb
Overview
Represents a ActiveRecord belongs_to association
Instance Attribute Summary collapse
-
#association_primary_key_column ⇒ Object
readonly
Returns the value of attribute association_primary_key_column.
-
#destination_model ⇒ Object
readonly
Returns the value of attribute destination_model.
-
#foreign_key_column ⇒ Object
readonly
Returns the value of attribute foreign_key_column.
-
#foreign_type_column ⇒ Object
readonly
Returns the value of attribute foreign_type_column.
-
#source_model ⇒ Object
readonly
Returns the value of attribute source_model.
Instance Method Summary collapse
-
#==(other) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #destination_model_name ⇒ Object
- #destination_table ⇒ Object
-
#initialize(source_model:, destination_model:, foreign_key_column:, association_primary_key_column: 'id', foreign_type_column: nil, **_extra) ⇒ BelongsToAssociation
constructor
A new instance of BelongsToAssociation.
- #polymorphic? ⇒ Boolean
- #source_table ⇒ Object
Constructor Details
#initialize(source_model:, destination_model:, foreign_key_column:, association_primary_key_column: 'id', foreign_type_column: nil, **_extra) ⇒ BelongsToAssociation
Returns a new instance of BelongsToAssociation.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/prune_ar/belongs_to_association.rb', line 12 def initialize( source_model:, destination_model:, foreign_key_column:, association_primary_key_column: 'id', foreign_type_column: nil, # Indicates that relation is polymorphic **_extra # Ignore extra ) @source_model = source_model @destination_model = destination_model @foreign_key_column = foreign_key_column @association_primary_key_column = association_primary_key_column @foreign_type_column = foreign_type_column end |
Instance Attribute Details
#association_primary_key_column ⇒ Object (readonly)
Returns the value of attribute association_primary_key_column.
6 7 8 |
# File 'lib/prune_ar/belongs_to_association.rb', line 6 def association_primary_key_column @association_primary_key_column end |
#destination_model ⇒ Object (readonly)
Returns the value of attribute destination_model.
6 7 8 |
# File 'lib/prune_ar/belongs_to_association.rb', line 6 def destination_model @destination_model end |
#foreign_key_column ⇒ Object (readonly)
Returns the value of attribute foreign_key_column.
6 7 8 |
# File 'lib/prune_ar/belongs_to_association.rb', line 6 def foreign_key_column @foreign_key_column end |
#foreign_type_column ⇒ Object (readonly)
Returns the value of attribute foreign_type_column.
6 7 8 |
# File 'lib/prune_ar/belongs_to_association.rb', line 6 def foreign_type_column @foreign_type_column end |
#source_model ⇒ Object (readonly)
Returns the value of attribute source_model.
6 7 8 |
# File 'lib/prune_ar/belongs_to_association.rb', line 6 def source_model @source_model end |
Instance Method Details
#==(other) ⇒ Object
rubocop:disable Metrics/AbcSize
43 44 45 46 47 48 49 |
# File 'lib/prune_ar/belongs_to_association.rb', line 43 def ==(other) # rubocop:disable Metrics/AbcSize source_model == other.source_model && destination_model == other.destination_model && foreign_key_column == other.foreign_key_column && association_primary_key_column == other.association_primary_key_column && foreign_type_column == other.foreign_type_column end |
#destination_model_name ⇒ Object
39 40 41 |
# File 'lib/prune_ar/belongs_to_association.rb', line 39 def destination_model_name destination_model.name end |
#destination_table ⇒ Object
35 36 37 |
# File 'lib/prune_ar/belongs_to_association.rb', line 35 def destination_table destination_model.table_name end |
#polymorphic? ⇒ Boolean
27 28 29 |
# File 'lib/prune_ar/belongs_to_association.rb', line 27 def polymorphic? !foreign_type_column.nil? end |
#source_table ⇒ Object
31 32 33 |
# File 'lib/prune_ar/belongs_to_association.rb', line 31 def source_table source_model.table_name end |