10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/schema_plus/core/sql_struct.rb', line 10
def parse!(sql)
m = sql.strip.match %r{
\A
(?<command>.*\bTABLE\b) \s*
(?<quote>['"`])(?<name>\S+)\k<quote> \s*
\( \s*
(?<body>.*) \s*
\) \s*
# can't use optional ? for inheritance because it would be greedily grabbed into body;
# ideally this would use an actual parser rather than regex
#{INHERITANCE_REGEX if sql.match INHERITANCE_REGEX}
(?<options> \S.*)?
\Z
}mxi
self.command = m[:command]
self.quotechar = m[:quote]
self.name = m[:name]
self.body = m[:body]
self.options = m[:options]
self.inheritance = m[:inheritance] rescue nil
end
|