Class: Graffiti::SquishAssert
- Inherits:
-
SquishQuery
- Object
- SquishQuery
- Graffiti::SquishAssert
- Defined in:
- lib/graffiti/squish.rb
Constant Summary
Constants inherited from SquishQuery
Graffiti::SquishQuery::AGGREGATE, Graffiti::SquishQuery::BN, Graffiti::SquishQuery::BN_SCAN, Graffiti::SquishQuery::INTERNAL, Graffiti::SquishQuery::LITERAL, Graffiti::SquishQuery::LITERAL_SCAN, Graffiti::SquishQuery::NUMBER, Graffiti::SquishQuery::OPERATOR, Graffiti::SquishQuery::PARAMETER, Graffiti::SquishQuery::PARAMETER_AND_LITERAL_SCAN, Graffiti::SquishQuery::QUERY
Instance Attribute Summary collapse
-
#insert ⇒ Object
readonly
Returns the value of attribute insert.
-
#update ⇒ Object
readonly
Returns the value of attribute update.
Attributes inherited from SquishQuery
#group, #literal, #nodes, #ns, #order, #order_dir, #pattern, #variables
Instance Method Summary collapse
-
#initialize(config, query) ⇒ SquishAssert
constructor
A new instance of SquishAssert.
- #run(db, params = {}) ⇒ Object
Methods inherited from SquishQuery
#ns_shrink, ns_shrink, #substitute_literals, #to_s, uri_shrink!, #validate_expression
Constructor Details
#initialize(config, query) ⇒ SquishAssert
Returns a new instance of SquishAssert.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/graffiti/squish.rb', line 316 def initialize(config, query) @config = config super(@config, query) if 'UPDATE' == @key @insert = '' @update = @nodes elsif 'INSERT' == @key and @nodes =~ /\A\s*(.*?)\s*(?:\bUPDATE\b\s*(.*?))?\s*\z/ @insert, @update = $1, $2.to_s else raise ProgrammingError, "Wrong query type: INSERT or UPDATE expected instead of " + @key end @insert = @insert.split(/\s*,\s*/).each {|s| s =~ BN or raise ProgrammingError, "Blank node expected in INSERT section instead of '#{s}'" } @update = @update.empty? ? {} : Hash[*@update.split(/\s*,\s*/).collect {|s| s.split(/\s*=\s*/) }.each {|node, value| node =~ BN or raise ProgrammingError, "Blank node expected on the left side of UPDATE assignment instead of '#{bn}'" validate_expression(value) }.flatten!] end |
Instance Attribute Details
#insert ⇒ Object (readonly)
Returns the value of attribute insert.
359 360 361 |
# File 'lib/graffiti/squish.rb', line 359 def insert @insert end |
#update ⇒ Object (readonly)
Returns the value of attribute update.
359 360 361 |
# File 'lib/graffiti/squish.rb', line 359 def update @update end |
Instance Method Details
#run(db, params = {}) ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/graffiti/squish.rb', line 346 def run(db, params={}) values = resource_values(db, params) statements = [] alias_positions.each do |alias_, clauses| statement = SquishAssertStatement.new(clauses, values) statements.push(statement) if statement.action end SquishAssertStatement.run_ordered_statements(db, statements) return @insert.collect {|node| values[node].value } end |