lib/veritas/relation/operation/order.rb in veritas-0.0.3 vs lib/veritas/relation/operation/order.rb in veritas-0.0.4

- old
+ new

@@ -1,13 +1,22 @@ +# encoding: utf-8 + module Veritas class Relation module Operation # A class representing a sorted relation class Order < Relation include Unary + # The relation sort order + # + # @return [Operation::Order::DirectionSet] + # + # @api private + attr_reader :directions + # Instantiate a new Order # # @example # order = Order.new(operand, directions) # @@ -75,13 +84,13 @@ # each tuple in the set # # @return [self] # # @api public - def each(&block) + def each return to_enum unless block_given? - directions.sort_tuples(operand).each(&block) + directions.sort_tuples(operand).each { |tuple| yield tuple } self end # Compare the Order with other relation for equality # @@ -115,25 +124,24 @@ # Return an ordered relation # # @example with no directions # order = relation.order # sort by the header # - # @example with directions - # order = relation.order([ relation[:a].desc, relation[:b] ]) - # # @example with a block # order = relation.order { |r| [ r[:a].desc, r[:b] ] } # # @yield [relation] # optional block to evaluate for directions # # @yieldparam [Relation] relation # + # @yieldreturn [Array<Direction>, Header] + # # @return [Order] # # @api public - def order(directions = block_given? ? Array(yield(self)) : header) - Order.new(self, directions) + def order + Order.new(self, block_given? ? Array(yield(self)) : header) end end # module Methods Relation.class_eval { include Methods }