Class: TableCopy::PG::Field
- Inherits:
-
Object
- Object
- TableCopy::PG::Field
- Defined in:
- lib/table_copy/pg/field.rb
Instance Attribute Summary collapse
-
#data_limit ⇒ Object
readonly
Returns the value of attribute data_limit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type_name ⇒ Object
readonly
Returns the value of attribute type_name.
Instance Method Summary collapse
- #auto_index? ⇒ Boolean
- #ddl ⇒ Object
-
#initialize(attrs) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(attrs) ⇒ Field
Returns a new instance of Field.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/table_copy/pg/field.rb', line 6 def initialize(attrs) @name = attrs['column_name'] data_type = attrs['data_type'] if data_type =~ /character/ @data_limit = attrs['character_maximum_length'] end if data_type == 'ARRAY' && attrs['udt_name'] == '_varchar' @type_name = 'character varying' @data_limit = '256' @array_ddl = '[]' end @type_name ||= data_type end |
Instance Attribute Details
#data_limit ⇒ Object (readonly)
Returns the value of attribute data_limit.
4 5 6 |
# File 'lib/table_copy/pg/field.rb', line 4 def data_limit @data_limit end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/table_copy/pg/field.rb', line 4 def name @name end |
#type_name ⇒ Object (readonly)
Returns the value of attribute type_name.
4 5 6 |
# File 'lib/table_copy/pg/field.rb', line 4 def type_name @type_name end |
Instance Method Details
#auto_index? ⇒ Boolean
27 28 29 |
# File 'lib/table_copy/pg/field.rb', line 27 def auto_index? @type_name =~ /int|timestamp|bool/ end |
#ddl ⇒ Object
23 24 25 |
# File 'lib/table_copy/pg/field.rb', line 23 def ddl @ddl ||= "#{name} #{type_name}#{data_limit_ddl}#{array_ddl}" end |