Class: Hotdog::Expression::QueryExpressionNode

Inherits:
ExpressionNode show all
Defined in:
lib/hotdog/expression/semantics.rb

Direct Known Subclasses

EverythingNode, NothingNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExpressionNode

#==, #optimize

Constructor Details

#initialize(query, values = [], options = {}) ⇒ QueryExpressionNode

Returns a new instance of QueryExpressionNode.



420
421
422
423
424
# File 'lib/hotdog/expression/semantics.rb', line 420

def initialize(query, values=[], options={})
  @query = query
  @values = values
  @fallback = options[:fallback]
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



425
426
427
# File 'lib/hotdog/expression/semantics.rb', line 425

def query
  @query
end

#valuesObject (readonly)

Returns the value of attribute values.



426
427
428
# File 'lib/hotdog/expression/semantics.rb', line 426

def values
  @values
end

Instance Method Details

#dump(options = {}) ⇒ Object



437
438
439
440
441
# File 'lib/hotdog/expression/semantics.rb', line 437

def dump(options={})
  data = {query: @query, values: @values}
  data[:fallback] = @fallback.dump(options) if @fallback
  data
end

#evaluate(environment, options = {}) ⇒ Object



428
429
430
431
432
433
434
435
# File 'lib/hotdog/expression/semantics.rb', line 428

def evaluate(environment, options={})
  values = environment.execute(@query, @values).map { |row| row.first }
  if values.empty? and @fallback
    @fallback.evaluate(environment, options)
  else
    values
  end
end