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

#==, #compact, #optimize

Constructor Details

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

Returns a new instance of QueryExpressionNode.



471
472
473
474
475
# File 'lib/hotdog/expression/semantics.rb', line 471

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

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



476
477
478
# File 'lib/hotdog/expression/semantics.rb', line 476

def query
  @query
end

#valuesObject (readonly)

Returns the value of attribute values.



477
478
479
# File 'lib/hotdog/expression/semantics.rb', line 477

def values
  @values
end

Instance Method Details

#dump(options = {}) ⇒ Object



488
489
490
491
492
# File 'lib/hotdog/expression/semantics.rb', line 488

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

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



479
480
481
482
483
484
485
486
# File 'lib/hotdog/expression/semantics.rb', line 479

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