Class: Axiom::Evaluator::Context

Inherits:
BasicObject
Extended by:
Aliasable
Defined in:
lib/axiom/support/evaluator.rb

Overview

Provide a context to evaluate a Relation operation block

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Aliasable

inheritable_alias

Constructor Details

#initialize(header) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a Context

Parameters:

  • header (Header)


33
34
35
36
37
38
# File 'lib/axiom/support/evaluator.rb', line 33

def initialize(header)
  @header    = header
  @functions = ::Hash.new
  @yield     = yield self
  @functions.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Attribute (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lookup the attribute in the header using the attribute name

Examples:

attribute = context.id

Parameters:

  • name (Symbol)

Returns:



114
115
116
117
118
# File 'lib/axiom/support/evaluator.rb', line 114

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

Instance Attribute Details

#functionsHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The functions to evaluate

Returns:

  • (Hash)


17
18
19
# File 'lib/axiom/support/evaluator.rb', line 17

def functions
  @functions
end

#yieldObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the block results

Returns:

  • (Object)


24
25
26
# File 'lib/axiom/support/evaluator.rb', line 24

def yield
  @yield
end

Instance Method Details

#[](name) ⇒ Attribute

Lookup the attribute in the header

Examples:

attribute = context[name]

Parameters:

  • name (Symbol)

Returns:



76
77
78
# File 'lib/axiom/support/evaluator.rb', line 76

def [](name)
  @header[name]
end

#add(attribute, object = Undefined) { ... } ⇒ self

Add a function to be evaluated by the summarization operation

Examples:

of a function

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

of a block

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

Parameters:

  • attribute (Attribute, #to_ary, #to_sym)

    the attribute to add to the header

  • object (Object) (defaults to: Undefined)

    optional object

Yields:

  • optional block to execute in the summarization operation

Returns:

  • (self)


59
60
61
62
63
64
# 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)
  functions[type.coerce(attribute)] = object
  self
end

#respond_to?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test if the method is supported on this object

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


87
88
89
# File 'lib/axiom/support/evaluator.rb', line 87

def respond_to?(name, *)
  @header.any? { |attribute| attribute.name.equal?(name) }
end

#send(*args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Forward a message to the object

Parameters:

  • args (Array)

Returns:

  • (Object)


98
99
100
# File 'lib/axiom/support/evaluator.rb', line 98

def send(*args, &block)
  __send__(*args, &block)
end