Sha256: eaadfd34f9d73869f929c9554e80f2a64d4efe43b12826d8e91cc3de8a801910

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

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

      # ConstantEnv receives an TypeName as a context, not a Namespace, because this is a simulation of Ruby.
      # Any namespace is a module or class.
      def initialize(factory:, context:, resolver:)
        @cache = {}
        @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
        resolver.constants(context).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)
        if constant
          [
            factory.type(constant.type),
            constant.name,
            constant.entry
          ]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
steep-1.0.2 lib/steep/type_inference/constant_env.rb
steep-1.0.1 lib/steep/type_inference/constant_env.rb
steep-1.0.0 lib/steep/type_inference/constant_env.rb
steep-0.52.2 lib/steep/type_inference/constant_env.rb
steep-0.52.1 lib/steep/type_inference/constant_env.rb
steep-0.52.0 lib/steep/type_inference/constant_env.rb
steep-0.51.0 lib/steep/type_inference/constant_env.rb