Class: SchemaPlus::Core::SqlStruct::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_plus/core/sql_struct.rb

Instance Method Summary collapse

Instance Method Details

#assembleObject



24
25
26
# File 'lib/schema_plus/core/sql_struct.rb', line 24

def assemble
  ["#{command} #{quotechar}#{name}#{quotechar} (#{body})", options].reject(&:blank?).join(" ")
end

#parse!(sql) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/schema_plus/core/sql_struct.rb', line 7

def parse!(sql)
  m = sql.strip.match %r{
  ^
  (?<command>.*\bTABLE\b) \s*
    (?<quote>['"`])(?<name>\S+)\k<quote> \s*
    \( \s*
    (?<body>.*) \s*
    \) \s*
    (?<options> \S.*)?
    $
  }xi
  self.command = m[:command]
  self.quotechar = m[:quote]
  self.name = m[:name]
  self.body = m[:body]
  self.options = m[:options]
end