Sha256: fbfbda0355bd66a591e440724b36c0a049b75af72b38faa3d14a970fcdbdf3f9

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8

module Axiom
  class Relation
    module Operation

      # A mixin for Set relations
      module Set
        include Binary

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

        private_class_method :included

        # Initialize a Set
        #
        # @param [Relation] _left
        # @param [Relation] _right
        #
        # @return [undefined]
        #
        # @api private
        def initialize(_left, _right)
          super
          @header = left.header
        end

        module ClassMethods

          # Instantiate a new Set relation
          #
          # @example
          #   set = SetRelation.new(left, right)
          #
          # @param [Array(Relation, Relation)] args
          #
          # @return [Set]
          #
          # @api public
          def new(*args)
            assert_equivalent_headers(*args)
            super
          end

        private

          # Assert that left and right have equivalent headers
          #
          # @param [Relation] left
          # @param [Relation] right
          #
          # @return [undefined]
          #
          # @raise [InvalidHeaderError]
          #   raised if the headers are not equivalent
          #
          # @api private
          def assert_equivalent_headers(left, right)
            if left.header != right.header
              raise InvalidHeaderError, 'the headers must be equivalent'
            end
          end

        end # module ClassMethods
      end # module Set
    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/set.rb
axiom-0.1.0 lib/axiom/relation/operation/set.rb