Sha256: 8977b036c087b0ec11958d93978f95573746b3bcafa29a09e119770081d3b132

Contents?: true

Size: 1.24 KB

Versions: 37

Compression:

Stored size: 1.24 KB

Contents

module Steep
  module TypeInference
    class ConstantEnv
      attr_reader :context
      attr_reader :factory
      attr_reader :resolver

      def initialize(factory:, context:, resolver:)
        @factory = factory
        @context = context
        @resolver = resolver
      end

      def resolve(name)
        decompose_constant(
          resolver.resolve(name, context: context)
        )
      end

      def toplevel(name)
        decompose_constant(
          resolver.table.toplevel[name]
        )
      end

      def constants
        cs = resolver.constants(context) or raise
        cs.transform_values {|c| decompose_constant!(c) }
      end

      def resolve_child(module_name, constant_name)
        decompose_constant(
          resolver.resolve_child(module_name, constant_name)
        )
      end

      def children(module_name)
        resolver.children(module_name).transform_values {|c| decompose_constant!(c) }
      end

      def decompose_constant!(constant)
        decompose_constant(constant) || raise
      end

      def decompose_constant(constant)
        if constant
          [
            factory.type(constant.type),
            constant.name,
            constant.entry
          ]
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
steep-1.9.1 lib/steep/type_inference/constant_env.rb
steep-1.9.0 lib/steep/type_inference/constant_env.rb
steep-1.9.0.dev.2 lib/steep/type_inference/constant_env.rb
steep-1.9.0.dev.1 lib/steep/type_inference/constant_env.rb
steep-1.8.3 lib/steep/type_inference/constant_env.rb
steep-1.8.2 lib/steep/type_inference/constant_env.rb
steep-1.8.1 lib/steep/type_inference/constant_env.rb
steep-1.8.0 lib/steep/type_inference/constant_env.rb
steep-1.8.0.pre.2 lib/steep/type_inference/constant_env.rb
steep-1.8.0.pre.1 lib/steep/type_inference/constant_env.rb
steep-1.8.0.dev.2 lib/steep/type_inference/constant_env.rb
steep-1.8.0.dev.1 lib/steep/type_inference/constant_env.rb
steep-1.7.1 lib/steep/type_inference/constant_env.rb
steep-1.7.0 lib/steep/type_inference/constant_env.rb
steep-1.7.0.dev.3 lib/steep/type_inference/constant_env.rb
steep-1.7.0.dev.2 lib/steep/type_inference/constant_env.rb
steep-1.7.0.dev.1 lib/steep/type_inference/constant_env.rb
steep-1.6.0 lib/steep/type_inference/constant_env.rb
steep-1.6.0.pre.4 lib/steep/type_inference/constant_env.rb
steep-1.6.0.pre.3 lib/steep/type_inference/constant_env.rb