class Cql::Model::Query::UpdateExpression
@TODO docs
Constants
- OPERATORS
Operators allowed in an update lambda
Public Class Methods
new(&block)
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 14 def initialize(&block) @left = nil @operator = nil @right = nil instance_exec(&block) if block end
Public Instance Methods
inspect()
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 28 def inspect __build__ end
method_missing(token, *args)
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 41 def method_missing(token, *args) __apply__(token, args) end
to_s()
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 23 def to_s __build__ end
Private Instance Methods
__apply__(token, args)
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 48 def __apply__(token, args) if @left.nil? if args.empty? # A well-behaved CQL identifier (column name that is a valid Ruby method name) @left = token elsif args.length == 1 # A CQL typecast (column name that is an integer, float, etc and must be wrapped in a decorator) @left = args.first else ::Kernel.raise ::Cql::Model::SyntaxError.new( "Unacceptable token '#{token}'; expected a CQL identifier or typecast") end elsif @operator.nil? # Looking for an operator + right operand if OPERATORS.keys.include?(token) @operator = token if (token == :[]=) @right = args # the right-hand argument of []= is a (key, value) pair else @right = args.first end else ::Kernel.raise ::Cql::Model::SyntaxError.new( "Unacceptable token '#{token}'; expected a CQL-compatible operator") end else ::Kernel.raise ::Cql::Model::SyntaxError.new( "Unacceptable token '#{token}'; the expression is " + "already complete") end self end
__build__()
click to toggle source
@TODO docs
# File lib/cql/model/query/update_expression.rb, line 84 def __build__ if @left.nil? || @operator.nil? || @right.nil? ::Kernel.raise ::Cql::Model::SyntaxError.new( "Cannot build a CQL expression; the Ruby expression is incomplete " + "(#{@left.inspect}, #{@operator.inspect}, #{@right.inspect})") else left = ::Cql::Model::Query.cql_identifier(@left) case @operator when :[]= key = ::Cql::Model::Query.cql_value(@right[0], context=:update) val = ::Cql::Model::Query.cql_value(@right[1], context=:update) "#{left}[#{key}] = #{val}" else op = OPERATORS[@operator] right = ::Cql::Model::Query.cql_value(@right, context=:update) "#{left} #{op} #{right}" end end end