Sha256: 2c6e7a34d15f8535c36acfea41df4aa95f19532ae77367ea241764f08bb3cdf0

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8

module Axiom
  class Relation
    module Operation

      # A mixin for Binary relations
      module Binary
        include Axiom::Operation::Binary

        # Hook called when module is included
        #
        # @param [Module] descendant
        #   the module or class including Binary
        #
        # @return [undefined]
        #
        # @api private
        def self.included(descendant)
          super
          descendant.extend(ClassMethods)
        end

        private_class_method :included

        # Initialize a Binary relation
        #
        # @return [undefined]
        #
        # @api private
        def initialize(*)
          super
          @header = left.header | right.header
        end

        module ClassMethods

          # Instantiate a new Binary relation
          #
          # @example
          #   binary = BinaryRelation.new(left, right)
          #
          # @param [Relation] left
          # @param [Relation] right
          #
          # @return [Binary]
          #
          # @api public
          def new(left, right)
            assert_ordered_match(left, right)
            super
          end

        private

          # Assert that ordered and unordered relations are not mixed
          #
          # @param [Relation] left
          # @param [Relation] right
          #
          # @return [undefined]
          #
          # @raise [RelationMismatchError]
          #   raised if one relation is ordered and the other is not
          #
          # @api private
          def assert_ordered_match(left, right)
            if left.directions.empty? != right.directions.empty?
              raise RelationMismatchError, 'both relations must be ordered or neither may be ordered'
            end
          end

        end # module ClassMethods
      end # module Binary
    end # module Operation
  end # class Relation
end # module Axiom

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.1.1 lib/axiom/relation/operation/binary.rb
axiom-0.1.0 lib/axiom/relation/operation/binary.rb