Class: Sortiri::ActiveRecord::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/sortiri/active_record/column.rb

Direct Known Subclasses

ForeignColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, model:, association_name: nil) ⇒ Column

Returns a new instance of Column.


8
9
10
11
12
# File 'lib/sortiri/active_record/column.rb', line 8

def initialize(name:, model:, association_name: nil)
  @name = name.to_s
  @model = model
  @association_name = association_name
end

Instance Attribute Details

#association_nameObject (readonly)

Returns the value of attribute association_name.


6
7
8
# File 'lib/sortiri/active_record/column.rb', line 6

def association_name
  @association_name
end

#nameObject (readonly)

Returns the value of attribute name.


6
7
8
# File 'lib/sortiri/active_record/column.rb', line 6

def name
  @name
end

Instance Method Details

#matches_with?(column_object) ⇒ Boolean

Returns:

  • (Boolean)

18
19
20
21
22
# File 'lib/sortiri/active_record/column.rb', line 18

def matches_with?(column_object)
  return false unless column_object.is_a?(Sortiri::Column)

  name == column_object.name && association_name.to_s == column_object.association.to_s
end

#name_with_table_nameObject


14
15
16
# File 'lib/sortiri/active_record/column.rb', line 14

def name_with_table_name
  [table_name, name].join('.')
end

#table_nameObject


24
25
26
# File 'lib/sortiri/active_record/column.rb', line 24

def table_name
  @model.table_name
end