Class: Hasten::Table
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#<<, #complete?, #sql, #type
Class Method Details
.match?(sql) ⇒ Boolean
5
6
7
|
# File 'lib/hasten/commands/table.rb', line 5
def self.match?(sql)
sql.match(/^CREATE\s+(TEMPORARY\s+)*TABLE/i)
end
|
Instance Method Details
#index_statements ⇒ Object
27
28
29
30
|
# File 'lib/hasten/commands/table.rb', line 27
def index_statements
indexes
.map { |definition| "ALTER TABLE `#{name}` ADD #{definition};" }
end
|
#indexes ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/hasten/commands/table.rb', line 19
def indexes
self
.select(&index_line)
.map{ |line| line.gsub(/^\s+/,'') }
.map{ |line| line.gsub(/,\s*$/,'') }
.map{ |line| line.chomp }
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/hasten/commands/table.rb', line 9
def name
sql[/(?<=`).*?(?=`)/]
end
|
#without_indexes ⇒ Object
13
14
15
16
17
|
# File 'lib/hasten/commands/table.rb', line 13
def without_indexes
revised = reject &index_line
revised[-2].gsub!(/,$/,'')
revised
end
|