Class: Hasten::Table

Inherits:
Command
  • Object
show all
Defined in:
lib/hasten/commands/table.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#<<, #complete?, #sql, #type

Class Method Details

.match?(sql) ⇒ Boolean

Returns:

  • (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_statementsObject



27
28
29
30
# File 'lib/hasten/commands/table.rb', line 27

def index_statements
  indexes
    .map { |definition| "ALTER TABLE `#{name}` ADD #{definition};" }
end

#indexesObject



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

#nameObject



9
10
11
# File 'lib/hasten/commands/table.rb', line 9

def name
  sql[/(?<=`).*?(?=`)/]
end

#without_indexesObject



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