Class: SchemaPlus::Core::SqlStruct::Table
- Inherits:
-
Struct
- Object
- Struct
- SchemaPlus::Core::SqlStruct::Table
- Defined in:
- lib/schema_plus/core/sql_struct.rb
Constant Summary collapse
- INHERITANCE_REGEX =
%r{ \s* (?<inheritance>INHERITS \s* \( [^)]* \)) }mxi
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#command ⇒ Object
Returns the value of attribute command.
-
#inheritance ⇒ Object
Returns the value of attribute inheritance.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#quotechar ⇒ Object
Returns the value of attribute quotechar.
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def body @body end |
#command ⇒ Object
Returns the value of attribute command
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def command @command end |
#inheritance ⇒ Object
Returns the value of attribute inheritance
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def inheritance @inheritance end |
#name ⇒ Object
Returns the value of attribute name
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def end |
#quotechar ⇒ Object
Returns the value of attribute quotechar
8 9 10 |
# File 'lib/schema_plus/core/sql_struct.rb', line 8 def quotechar @quotechar end |
Instance Method Details
#assemble ⇒ Object
33 34 35 |
# File 'lib/schema_plus/core/sql_struct.rb', line 33 def assemble ["#{command} #{quotechar}#{name}#{quotechar} (#{body})", inheritance, ].reject(&:blank?).join(" ") end |
#parse!(sql) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/schema_plus/core/sql_struct.rb', line 12 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. = m[:options] self.inheritance = m[:inheritance] rescue nil end |