Class: Ronin::Code::SQL::Statement
- Defined in:
- lib/ronin/code/sql/statement.rb
Direct Known Subclasses
AlterTable, Create, Delete, Drop, InjectedStatement, Insert, Replace, Select, Update
Instance Attribute Summary collapse
-
#clauses ⇒ Object
readonly
Returns the value of attribute clauses.
Class Method Summary collapse
-
.clause_order ⇒ Object
Returns the Array denoting the precedence of clauses provided by the statement.
-
.clauses ⇒ Object
Returns the Hash of the clause names and the Clause classes provided by the statement.
-
.has_clause?(name) ⇒ Boolean
Returns
trueif the statement provides a clause with the specified name, returnsfalseotherwise.
Instance Method Summary collapse
-
#emit ⇒ Object
Returns an Array of unformatted tokens that represent the statement.
-
#get_clause(name) ⇒ Object
Returns the clause with the specified name.
-
#has_clause?(name) ⇒ Boolean
Returns
trueif the statement has a clause with the specified name, returnsfalseotherwise. -
#initialize(dialect, options = {}, &block) ⇒ Statement
constructor
Creates a new Statement object connected to the specified dialect.
Methods inherited from Expr
Constructor Details
#initialize(dialect, options = {}, &block) ⇒ Statement
Creates a new Statement object connected to the specified dialect. If a block is given, it will be evaluated within the newly created Statement object.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ronin/code/sql/statement.rb', line 43 def initialize(dialect,={},&block) super() @dialect = dialect @clauses = [] .each do |name,args| if self.class.has_clause?(name) clause(name,*args) end end instance_eval(&block) if block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ Object (protected)
167 168 169 170 171 172 173 174 175 |
# File 'lib/ronin/code/sql/statement.rb', line 167 def method_missing(name,*arguments,&block) if @dialect.has_statement?(name) return @dialect.statement(name,*arguments,&block) elsif @dialect.class.public_method_defined?(name) return @dialect.send(name,*arguments,&block) elsif (arguments.empty? && block.nil?) return @dialect.field(name) end end |
Instance Attribute Details
#clauses ⇒ Object (readonly)
Returns the value of attribute clauses.
36 37 38 |
# File 'lib/ronin/code/sql/statement.rb', line 36 def clauses @clauses end |
Class Method Details
.clause_order ⇒ Object
Returns the Array denoting the precedence of clauses provided by the statement.
62 63 64 |
# File 'lib/ronin/code/sql/statement.rb', line 62 def self.clause_order @@clause_order ||= [] end |
.clauses ⇒ Object
Returns the Hash of the clause names and the Clause classes provided by the statement.
70 71 72 |
# File 'lib/ronin/code/sql/statement.rb', line 70 def self.clauses @@clauses ||= {} end |
.has_clause?(name) ⇒ Boolean
Returns true if the statement provides a clause with the specified name, returns false otherwise.
78 79 80 |
# File 'lib/ronin/code/sql/statement.rb', line 78 def self.has_clause?(name) self.clauses.has_key?(name.to_sym) end |
Instance Method Details
#emit ⇒ Object
Returns an Array of unformatted tokens that represent the statement.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ronin/code/sql/statement.rb', line 105 def emit tokens = [] @clauses.each do |clause| if clause tokens += clause.emit end end return tokens end |
#get_clause(name) ⇒ Object
Returns the clause with the specified name.
95 96 97 98 99 |
# File 'lib/ronin/code/sql/statement.rb', line 95 def get_clause(name) index = self.class.clause_order.index(name.to_sym) return @clauses[index] end |
#has_clause?(name) ⇒ Boolean
Returns true if the statement has a clause with the specified name, returns false otherwise.
86 87 88 89 90 |
# File 'lib/ronin/code/sql/statement.rb', line 86 def has_clause?(name) index = self.class.clause_order.index(name.to_sym) return !(@clauses[index].nil?) end |