Class: TableSaw::ForeignKey::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/table_saw/foreign_key.rb

Constant Summary collapse

REGEX =
/(\w+)(?::(\w+)\((\w+)\))?/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Column

Returns a new instance of Column.



10
11
12
# File 'lib/table_saw/foreign_key.rb', line 10

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/table_saw/foreign_key.rb', line 8

def value
  @value
end

Instance Method Details

#primary_keyObject



14
15
16
# File 'lib/table_saw/foreign_key.rb', line 14

def primary_key
  value[REGEX, 1]
end

#type_conditionObject



18
19
20
# File 'lib/table_saw/foreign_key.rb', line 18

def type_condition
  polymorphic? ? "#{type_column} = '#{type_value}'" : '1 = 1'
end