Sha256: 4c385f2b109a9a82351c7abcc5f61355dcbe87b8722f55790494a701db1c24ef

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

module Steep
  module Interface
    class Interface
      class Combination
        attr_reader :operator
        attr_reader :types

        def initialize(operator:, types:)
          @types = types
          @operator = operator
          @incompatible = false
        end

        def overload?
          operator == :overload
        end

        def union?
          operator == :union
        end

        def intersection?
          operator == :intersection
        end

        def self.overload(types, incompatible:)
          new(operator: :overload, types: types).incompatible!(incompatible)
        end

        def incompatible?
          @incompatible
        end

        def incompatible!(value)
          @incompatible = value
          self
        end

        def self.union(types)
          case types.size
          when 0
            raise "Combination.union called with zero types"
          when 1
            types.first
          else
            new(operator: :union, types: types)
          end
        end

        def self.intersection(types)
          case types.size
          when 0
            raise "Combination.intersection called with zero types"
          when 1
            types.first
          else
            new(operator: :intersection, types: types)
          end
        end

        def to_s
          case operator
          when :overload
            "{ #{types.map(&:to_s).join(" | ")} }"
          when :union
            "[#{types.map(&:to_s).join(" | ")}]"
          when :intersection
            "[#{types.map(&:to_s).join(" & ")}]"
          end
        end
      end

      attr_reader :type
      attr_reader :methods

      def initialize(type:, private:)
        @type = type
        @private = private
        @methods = {}
      end

      def private?
        @private
      end

      def public?
        !private?
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
steep-0.27.0 lib/steep/interface/interface.rb
steep-0.25.0 lib/steep/interface/interface.rb
steep-0.24.0 lib/steep/interface/interface.rb
steep-0.23.0 lib/steep/interface/interface.rb
steep-0.22.0 lib/steep/interface/interface.rb
steep-0.21.0 lib/steep/interface/interface.rb
steep-0.20.0 lib/steep/interface/interface.rb
steep-0.19.0 lib/steep/interface/interface.rb
steep-0.18.0 lib/steep/interface/interface.rb
steep-0.17.1 lib/steep/interface/interface.rb
steep-0.17.0 lib/steep/interface/interface.rb
steep-0.16.3 lib/steep/interface/interface.rb
steep-0.16.2 lib/steep/interface/interface.rb
steep-0.16.1 lib/steep/interface/interface.rb
steep-0.16.0 lib/steep/interface/interface.rb
steep-0.15.0 lib/steep/interface/interface.rb
steep-0.14.0 lib/steep/interface/interface.rb
steep-0.13.0 lib/steep/interface/interface.rb
steep-0.12.0 lib/steep/interface/interface.rb