class Axiom::Evaluator::Context

Provide a context to evaluate a Relation operation block

Attributes

functions[R]

The functions to evaluate

@return [Hash]

@api private

yield[R]

Return the block results

@return [Object]

@api private

Public Class Methods

new(header) { |self| ... } click to toggle source

Initialize a Context

@param [Header] header

@return [undefined]

@api private

# File lib/axiom/support/evaluator.rb, line 33
def initialize(header)
  @header    = header
  @functions = ::Hash.new
  @yield     = yield self
  @functions.freeze
end

Public Instance Methods

[](name) click to toggle source

Lookup the attribute in the header

@example

attribute = context[name]

@param [Symbol] name

@return [Attribute]

@api public

# File lib/axiom/support/evaluator.rb, line 79
def [](name)
  @header[name]
end
add(attribute, object = Undefined, &block) click to toggle source

Add a function to be evaluated by the summarization operation

@example of a function

context.add(:total, context[:unit_price] * context[:quantity])

@example of a block

context.add(:total) { |tuple| tuple[:unit_price] * tuple[:quantity] } }

@param [Attribute, to_ary, to_sym] attribute

the attribute to add to the header

@param [Object] object

optional object

@yield []

optional block to execute in the summarization operation

@return [self]

@api public

# File lib/axiom/support/evaluator.rb, line 59
def add(attribute, object = Undefined, &block)
  object = block if object.equal?(Undefined)
  type   = Attribute.infer_type(object)
  klass  = Attribute.descendants.detect do |descendant|
    descendant.type >= type
  end
  functions[klass.coerce(attribute)] = object
  self
end
respond_to?(name, *) click to toggle source

Test if the method is supported on this object

@param [Symbol] name

@return [Boolean]

@api private

# File lib/axiom/support/evaluator.rb, line 90
def respond_to?(name, *)
  @header.any? { |attribute| attribute.name.equal?(name) }
end
send(*args, &block) click to toggle source

Forward a message to the object

@param [Array] args

@return [Object]

@api private

# File lib/axiom/support/evaluator.rb, line 101
def send(*args, &block)
  __send__(*args, &block)
end

Private Instance Methods

method_missing(name, *args) click to toggle source

Lookup the attribute in the header using the attribute name

@example

attribute = context.id

@param [Symbol] name

@return [Attribute]

@api private

Calls superclass method
# File lib/axiom/support/evaluator.rb, line 117
def method_missing(name, *args)
  super unless respond_to?(name)
  ::Kernel.raise ::ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
  self[name]
end