lib/lhm/table.rb in lhm-2.1.0 vs lib/lhm/table.rb in lhm-2.2.0
- old
+ new
@@ -5,20 +5,20 @@
module Lhm
class Table
attr_reader :name, :columns, :indices, :pk, :ddl
- def initialize(name, pk = "id", ddl = nil)
+ def initialize(name, pk = 'id', ddl = nil)
@name = name
@columns = {}
@indices = {}
@pk = pk
@ddl = ddl
end
def satisfies_primary_key?
- @pk == "id"
+ @pk == 'id'
end
def destination_name
"lhmn_#{ @name }"
end
@@ -43,14 +43,14 @@
def parse
schema = read_information_schema
Table.new(@table_name, extract_primary_key(schema), ddl).tap do |table|
schema.each do |defn|
- column_name = struct_key(defn, "COLUMN_NAME")
- column_type = struct_key(defn, "COLUMN_TYPE")
- is_nullable = struct_key(defn, "IS_NULLABLE")
- column_default = struct_key(defn, "COLUMN_DEFAULT")
+ column_name = struct_key(defn, 'COLUMN_NAME')
+ column_type = struct_key(defn, 'COLUMN_TYPE')
+ is_nullable = struct_key(defn, 'IS_NULLABLE')
+ column_default = struct_key(defn, 'COLUMN_DEFAULT')
table.columns[defn[column_name]] = {
:type => defn[column_type],
:is_nullable => defn[is_nullable],
:column_default => defn[column_default]
}
@@ -81,27 +81,27 @@
end
def extract_indices(indices)
indices.
map do |row|
- key_name = struct_key(row, "Key_name")
- column_name = struct_key(row, "COLUMN_NAME")
+ key_name = struct_key(row, 'Key_name')
+ column_name = struct_key(row, 'COLUMN_NAME')
[row[key_name], row[column_name]]
end.
- inject(Hash.new { |h, k| h[k] = []}) do |memo, (idx, column)|
+ inject(Hash.new { |h, k| h[k] = [] }) do |memo, (idx, column)|
memo[idx] << column
memo
end
end
def extract_primary_key(schema)
cols = schema.select do |defn|
- column_key = struct_key(defn, "COLUMN_KEY")
- defn[column_key] == "PRI"
+ column_key = struct_key(defn, 'COLUMN_KEY')
+ defn[column_key] == 'PRI'
end
keys = cols.map do |defn|
- column_name = struct_key(defn, "COLUMN_NAME")
+ column_name = struct_key(defn, 'COLUMN_NAME')
defn[column_name]
end
keys.length == 1 ? keys.first : keys
end