lib/alf/operator/non_relational/defaults.rb in alf-0.10.1 vs lib/alf/operator/non_relational/defaults.rb in alf-0.11.0

- old
+ new

@@ -1,25 +1,22 @@ module Alf - module Operator::NonRelational - class Defaults < Alf::Operator() - include Operator::NonRelational, Operator::Transform - - signature do |s| - s.argument :defaults, TupleComputation, {} - s.option :strict, Boolean, false, "Restrict to default attributes only?" - end - - protected - - # (see Operator::Transform#_tuple2tuple) - def _tuple2tuple(tuple) - handle = TupleHandle.new.set(tuple) - defs = @defaults.evaluate(handle) - keys = @strict ? defs.keys : (tuple.keys | defs.keys) - tuple_collect(keys){|k| - [k, coalesce(tuple[k], defs[k])] - } - end - - end # class Defaults - end # module Operator::NonRelational + module Operator + module NonRelational + class Defaults + include NonRelational, Unary + + signature do |s| + s.argument :defaults, TupleComputation, {} + s.option :strict, Boolean, false, "Restrict to default attributes only?" + end + + # (see Operator#compile) + def compile + op = Engine::Defaults.new(operand, defaults) + op = Engine::Clip.new(op, defaults.to_attr_list, false) if strict + op + end + + end # class Defaults + end # module NonRelational + end # module Operator end # module Alf