lib/veritas/support/evaluator.rb in veritas-0.0.4 vs lib/veritas/support/evaluator.rb in veritas-0.0.5
- old
+ new
@@ -2,31 +2,37 @@
module Veritas
module Evaluator
# Provide a context to evaluate a Relation operation block
- class Context
- include Immutable
+ class Context < BasicObject
# The functions to evaluate
#
# @return [Hash]
#
# @api private
attr_reader :functions
+ # Return the block results
+ #
+ # @return [Object]
+ #
+ # @api private
+ attr_reader :yield
+
# Initialize a Context
#
# @param [Header] header
#
# @return [undefined]
#
# @api private
def initialize(header)
@header = header
@functions = {}
- yield self
+ @yield = yield self
@functions.freeze
end
# Add a function to be evaluated by the summarization operation
#
@@ -64,9 +70,49 @@
# @return [Attribute]
#
# @api public
def [](name)
@header[name]
+ end
+
+ # Test if the method is supported on this object
+ #
+ # @param [Symbol] name
+ #
+ # @return [Boolean]
+ #
+ # @api private
+ def respond_to?(name, *)
+ !!self[name]
+ end
+
+ # Forward a message to the object
+ #
+ # @param [Array] *args
+ #
+ # @return [Object]
+ #
+ # @api private
+ def send(*args, &block)
+ __send__(*args, &block)
+ end
+
+ private
+
+ # Lookup the attribute in the header using the attribute name
+ #
+ # @example
+ # attribute = context.id
+ #
+ # @param [Symbol] name
+ #
+ # @return [Attribute]
+ #
+ # @api private
+ def method_missing(name, *args)
+ return super unless respond_to?(name)
+ ::Kernel.raise ::ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
+ self[name]
end
end # class Context
end # module Evaluator
end # module Veritas