Class: Immigrate::ForeignTableDefinition
- Inherits:
-
Object
- Object
- Immigrate::ForeignTableDefinition
- Defined in:
- lib/immigrate/foreign_table_definition.rb
Constant Summary collapse
- NATIVE_DATABASE_TYPES =
{ string: 'character varying', text: 'text', integer: 'integer', float: 'float', decimal: 'decimal', datetime: 'timestamp', time: 'time', date: 'date', daterange: 'daterange', numrange: 'numrange', tsrange: 'tsrange', tstzrange: 'tstzrange', int4range: 'int4range', int8range: 'int8range', binary: 'bytea', boolean: 'boolean', xml: 'xml', tsvector: 'tsvector', hstore: 'hstore', inet: 'inet', cidr: 'cidr', macaddr: 'macaddr', uuid: 'uuid', json: 'json', jsonb: 'jsonb', ltree: 'ltree', citext: 'citext', point: 'point', line: 'line', lseg: 'lseg', box: 'box', path: 'path', polygon: 'polygon', circle: 'circle', bit: 'bit', bit_varying: 'bit varying', money: 'money', }
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #column(name, type) ⇒ Object
- #column_definitions ⇒ Object
-
#initialize(name, server) ⇒ ForeignTableDefinition
constructor
A new instance of ForeignTableDefinition.
- #native_column_type(type) ⇒ Object
- #sql ⇒ Object
Constructor Details
#initialize(name, server) ⇒ ForeignTableDefinition
Returns a new instance of ForeignTableDefinition.
45 46 47 48 49 |
# File 'lib/immigrate/foreign_table_definition.rb', line 45 def initialize name, server @name = name @server = server @columns = [] end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
43 44 45 |
# File 'lib/immigrate/foreign_table_definition.rb', line 43 def columns @columns end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/immigrate/foreign_table_definition.rb', line 43 def name @name end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
43 44 45 |
# File 'lib/immigrate/foreign_table_definition.rb', line 43 def server @server end |
Instance Method Details
#column(name, type) ⇒ Object
51 52 53 |
# File 'lib/immigrate/foreign_table_definition.rb', line 51 def column name, type @columns << [name, type] end |
#column_definitions ⇒ Object
67 68 69 |
# File 'lib/immigrate/foreign_table_definition.rb', line 67 def column_definitions columns.map { |column| "#{column.first} #{native_column_type column.second}"}.join(',') end |
#native_column_type(type) ⇒ Object
71 72 73 |
# File 'lib/immigrate/foreign_table_definition.rb', line 71 def native_column_type type NATIVE_DATABASE_TYPES[type] end |
#sql ⇒ Object
63 64 65 |
# File 'lib/immigrate/foreign_table_definition.rb', line 63 def sql "CREATE FOREIGN TABLE #{name} (#{column_definitions}) SERVER #{server}" end |