Class: SQLTree::Node::Field
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #field)
Returns the value of attribute name.
-
#table ⇒ Object
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, table = nil) ⇒ Field
constructor
A new instance of Field.
- #quote_var(name) ⇒ Object
- #to_sql ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(name, table = nil) ⇒ Field
Returns a new instance of Field.
10 11 12 13 |
# File 'lib/sql_tree/node/field.rb', line 10 def initialize(name, table = nil) @name = name @table = table end |
Instance Attribute Details
#name ⇒ Object Also known as: field
Returns the value of attribute name.
5 6 7 |
# File 'lib/sql_tree/node/field.rb', line 5 def name @name end |
#table ⇒ Object
Returns the value of attribute table.
5 6 7 |
# File 'lib/sql_tree/node/field.rb', line 5 def table @table end |
Class Method Details
.parse(tokens) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sql_tree/node/field.rb', line 28 def self.parse(tokens) field_or_table = case tokens.next when SQLTree::Token::MULTIPLY then :all when SQLTree::Token::Variable then tokens.current.literal else raise SQLTree::Parser::UnexpectedToken.new(tokens.current) end if tokens.peek == SQLTree::Token::DOT table = field_or_table tokens.consume(SQLTree::Token::DOT) field = case tokens.next when SQLTree::Token::MULTIPLY then :all when SQLTree::Token::Variable then tokens.current.literal else raise SQLTree::Parser::UnexpectedToken.new(tokens.current) end self.new(field, table) else self.new(field_or_table) end end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 |
# File 'lib/sql_tree/node/field.rb', line 24 def ==(other) other.name == self.name && other.table == self.table end |
#quote_var(name) ⇒ Object
15 16 17 18 |
# File 'lib/sql_tree/node/field.rb', line 15 def quote_var(name) return '*' if name == :all super(name) end |
#to_sql ⇒ Object
20 21 22 |
# File 'lib/sql_tree/node/field.rb', line 20 def to_sql @table.nil? ? quote_var(@name) : quote_var(@table) + '.' + quote_var(@name) end |