class Bmg::Operator::Constants

Constants operator.

Extends operand's tuples with attributes given at construction. This is a special case of an extension, where the values are statically known.

Attributes

constants[R]

Public Class Methods

new(type, operand, constants) click to toggle source
# File lib/bmg/operator/constants.rb, line 13
def initialize(type, operand, constants)
  @type = type
  @operand = operand
  @constants = constants
end

Public Instance Methods

delete() click to toggle source
# File lib/bmg/operator/constants.rb, line 50
def delete
  operand.delete
end
each() { |extend_it(tuple)| ... } click to toggle source
# File lib/bmg/operator/constants.rb, line 25
def each
  return to_enum unless block_given?
  @operand.each do |tuple|
    yield extend_it(tuple)
  end
end
insert(arg) click to toggle source
Calls superclass method
# File lib/bmg/operator/constants.rb, line 32
def insert(arg)
  case arg
  when Hash       then operand.insert(allbut_constants(arg))
  when Relation   then operand.insert(arg.allbut(constants.keys))
  when Enumerable then operand.insert(arg.map{|t| allbut_constants(t) })
  else
    super
  end
end
to_ast() click to toggle source
# File lib/bmg/operator/constants.rb, line 54
def to_ast
  [ :constants, operand.to_ast, constants.dup ]
end
update(tuple) click to toggle source
# File lib/bmg/operator/constants.rb, line 42
def update(tuple)
  shared = tuple.keys & constants.keys
  on_tuple = TupleAlgebra.project(tuple, shared)
  on_const = TupleAlgebra.project(constants, shared)
  raise InvalidUpdateError, "Cannot violate relvar predicate" unless on_tuple == on_const
  operand.update(allbut_constants(tuple))
end