Sha256: 0b26f97aa6b0072406e44ef21e06973f4e7d220f73dccf2b53ed6c5994dfe6c8

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module Alf
  module Algebra
    module TypeCheck

      def type_check_error!(msg)
        raise TypeCheckError, msg
      end

      def no_unknown!(unknown)
        unknown = unknown.to_a
        unless unknown.empty?
          msg = "#{to_s}: no such attribute"
          msg << ((unknown.size > 1) ? "s " : " ")
          msg << unknown.map{|a| "`#{a}`" }.join(',')
          type_check_error!(msg)
        end
      end
      private :no_unknown!

      def no_name_clash!(left, right)
        commons = (left & right).to_a
        unless commons.empty?
          msg = "#{to_s}: cannot override "
          msg << commons.map{|a| "`#{a}`" }.join(',')
          type_check_error!(msg)
        end
      end

      def valid_ordering!(ordering, attr_list)
        no_unknown!(ordering.to_attr_list - attr_list)
      end

      def same_heading!(left, right)
        unless left == right
          type_check_error!("heading mismatch `#{left}` vs. `#{right}`")
        end
      end

      def joinable_headings!(left, right, options)
        if options[:strict]
          commons = left.to_attr_list & right.to_attr_list
          left_h, right_h = left.project(commons), right.project(commons)
          same_heading!(left_h, right_h)
        else
          left & right
        end
      end

    end # module TypeCheck
  end # module Algebra
end # module Alf

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/algebra/support/type_check.rb
alf-core-0.16.2 lib/alf/algebra/support/type_check.rb
alf-core-0.16.1 lib/alf/algebra/support/type_check.rb
alf-core-0.16.0 lib/alf/algebra/support/type_check.rb
alf-core-0.15.0 lib/alf/algebra/support/type_check.rb