Class: Dry::Types::PrimitiveInferrer

Inherits:
Object
  • Object
show all
Extended by:
Core::Cache
Defined in:
lib/dry/types/primitive_inferrer.rb

Overview

PrimitiveInferrer returns the list of classes matching a type.

Defined Under Namespace

Classes: Compiler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrimitiveInferrer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PrimitiveInferrer.



79
80
81
# File 'lib/dry/types/primitive_inferrer.rb', line 79

def initialize
  @compiler = Compiler.new
end

Instance Attribute Details

#compilerCompiler (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



76
77
78
# File 'lib/dry/types/primitive_inferrer.rb', line 76

def compiler
  @compiler
end

Instance Method Details

#[](type) ⇒ Array[Class]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Infer primitives from the provided type

Returns:



88
89
90
91
92
# File 'lib/dry/types/primitive_inferrer.rb', line 88

def [](type)
  self.class.fetch_or_store(type) do
    Array(compiler.visit(type.to_ast)).freeze
  end
end