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.



388
389
390
391
392
# File 'lib/hotdog/expression/semantics.rb', line 388

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

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



393
394
395
# File 'lib/hotdog/expression/semantics.rb', line 393

def query
  @query
end

#valuesObject (readonly)

Returns the value of attribute values.



394
395
396
# File 'lib/hotdog/expression/semantics.rb', line 394

def values
  @values
end

Instance Method Details

#dump(options = {}) ⇒ Object



405
406
407
408
409
# File 'lib/hotdog/expression/semantics.rb', line 405

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

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



396
397
398
399
400
401
402
403
# File 'lib/hotdog/expression/semantics.rb', line 396

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