Class: PostgresToRedshift::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/postgres_to_redshift/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes:, columns: []) ⇒ Table

Returns a new instance of Table.



18
19
20
21
# File 'lib/postgres_to_redshift/table.rb', line 18

def initialize(attributes: , columns: [])
  self.attributes = attributes
  self.columns = columns
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



16
17
18
# File 'lib/postgres_to_redshift/table.rb', line 16

def attributes
  @attributes
end

#columnsObject

Returns the value of attribute columns.



16
17
18
# File 'lib/postgres_to_redshift/table.rb', line 16

def columns
  @columns
end

Instance Method Details

#columns_for_copyObject



44
45
46
47
48
# File 'lib/postgres_to_redshift/table.rb', line 44

def columns_for_copy
  columns.map do |column|
    column.name_for_copy
  end.join(", ")
end

#columns_for_createObject



38
39
40
41
42
# File 'lib/postgres_to_redshift/table.rb', line 38

def columns_for_create
  columns.map do |column|
    %Q["#{column.name}" #{column.data_type_for_copy}]
  end.join(", ")
end

#is_view?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/postgres_to_redshift/table.rb', line 50

def is_view?
  attributes["table_type"] == "VIEW"
end

#nameObject Also known as: to_s



23
24
25
# File 'lib/postgres_to_redshift/table.rb', line 23

def name
  attributes["table_name"]
end

#target_table_nameObject



28
29
30
# File 'lib/postgres_to_redshift/table.rb', line 28

def target_table_name
  name.gsub(/_view$/, '')
end