Class: Lhm::Table

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

Defined Under Namespace

Classes: Parser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pk = 'id', ddl = nil) ⇒ Table

Returns a new instance of Table.



10
11
12
13
14
15
16
17
# File 'lib/lhm/table.rb', line 10

def initialize(name, pk = 'id', ddl = nil)
  @name = name
  @table_name = TableName.new(name)
  @columns = {}
  @indices = {}
  @pk = pk
  @ddl = ddl
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



8
9
10
# File 'lib/lhm/table.rb', line 8

def columns
  @columns
end

#ddlObject (readonly)

Returns the value of attribute ddl.



8
9
10
# File 'lib/lhm/table.rb', line 8

def ddl
  @ddl
end

#indicesObject (readonly)

Returns the value of attribute indices.



8
9
10
# File 'lib/lhm/table.rb', line 8

def indices
  @indices
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/lhm/table.rb', line 8

def name
  @name
end

#pkObject (readonly)

Returns the value of attribute pk.



8
9
10
# File 'lib/lhm/table.rb', line 8

def pk
  @pk
end

Class Method Details

.parse(table_name, connection) ⇒ Object



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

def self.parse(table_name, connection)
  Parser.new(table_name, connection).parse
end

Instance Method Details

#destination_nameObject



24
25
26
# File 'lib/lhm/table.rb', line 24

def destination_name
  @destination_name ||= @table_name.new
end

#satisfies_id_column_requirement?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/lhm/table.rb', line 19

def satisfies_id_column_requirement?
  !!((id = columns['id']) &&
    id[:type] =~ /(bigint|int)(\(\d+\))?/)
end