Class: DataMigrations::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, name, alias_ = nil) ⇒ Column

Returns a new instance of Column.



5
6
7
8
9
# File 'lib/data_migrations/column.rb', line 5

def initialize(table, name, alias_ = nil)
  @table = table
  @name  = name
  @alias = alias_
end

Instance Attribute Details

#alias ⇒ Object (readonly)

Returns the value of attribute alias.



3
4
5
# File 'lib/data_migrations/column.rb', line 3

def alias
  @alias
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/data_migrations/column.rb', line 3

def name
  @name
end

#table ⇒ Object (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/data_migrations/column.rb', line 3

def table
  @table
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/data_migrations/column.rb', line 43

def ==(other)
  name == other.name
end

#aliased_name ⇒ Object



23
24
25
# File 'lib/data_migrations/column.rb', line 23

def aliased_name
  self.alias.present? ? "#{quote(name)} AS #{quote(self.alias)}" : quote(name)
end

#column ⇒ Object



19
20
21
# File 'lib/data_migrations/column.rb', line 19

def column
  table.column(name)
end

#definition ⇒ Object



11
12
13
# File 'lib/data_migrations/column.rb', line 11

def definition
  [quoted_alias_name, type].join(' ')
end

#quote(name) ⇒ Object



39
40
41
# File 'lib/data_migrations/column.rb', line 39

def quote(name)
  table.connection.quote_column_name(name)
end

#quote_value(value) ⇒ Object



35
36
37
# File 'lib/data_migrations/column.rb', line 35

def quote_value(value)
  table.connection.quote(value, column)
end

#quoted_alias_name ⇒ Object



31
32
33
# File 'lib/data_migrations/column.rb', line 31

def quoted_alias_name
  quote(self.alias.present? ? self.alias : name)
end

#quoted_name ⇒ Object



27
28
29
# File 'lib/data_migrations/column.rb', line 27

def quoted_name
  quote(name)
end

#type ⇒ Object



15
16
17
# File 'lib/data_migrations/column.rb', line 15

def type
  column.sql_type
end