Class: Pgerd::ForeignKey

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/pgerd/foreign_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ForeignKey



6
7
8
9
10
11
# File 'lib/pgerd/foreign_key.rb', line 6

def initialize(data)
  @from_table = data['from_table']
  @from_column = data['from_column']
  @to_table = data['to_table']
  @to_column = data['to_column']
end

Instance Attribute Details

#from_columnObject (readonly)

Returns the value of attribute from_column.



4
5
6
# File 'lib/pgerd/foreign_key.rb', line 4

def from_column
  @from_column
end

#from_tableObject (readonly)

Returns the value of attribute from_table.



4
5
6
# File 'lib/pgerd/foreign_key.rb', line 4

def from_table
  @from_table
end

#to_columnObject (readonly)

Returns the value of attribute to_column.



4
5
6
# File 'lib/pgerd/foreign_key.rb', line 4

def to_column
  @to_column
end

#to_tableObject (readonly)

Returns the value of attribute to_table.



4
5
6
# File 'lib/pgerd/foreign_key.rb', line 4

def to_table
  @to_table
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
# File 'lib/pgerd/foreign_key.rb', line 17

def <=>(other)
  to_a_for_sorting <=> other.to_a_for_sorting
end

#for_table?(table) ⇒ Boolean



25
26
27
# File 'lib/pgerd/foreign_key.rb', line 25

def for_table?(table)
  @from_table == table || @to_table == table
end

#to_a_for_sortingObject



21
22
23
# File 'lib/pgerd/foreign_key.rb', line 21

def to_a_for_sorting
  [@from_table, @from_column, @to_table, @to_column]
end

#to_sObject



13
14
15
# File 'lib/pgerd/foreign_key.rb', line 13

def to_s
  "#{@from_table}.#{@from_column} --> #{@to_table}.#{@to_column}"
end