Class: Dry::Schema::PredicateInferrer Private
- Inherits:
-
Object
- Object
- Dry::Schema::PredicateInferrer
- Extended by:
- Core::Cache
- Defined in:
- lib/dry/schema/predicate_inferrer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
PredicateInferrer is used internally by ‘Macros::Value` for inferring type-check predicates from type specs.
Defined Under Namespace
Classes: Compiler
Constant Summary collapse
- TYPE_TO_PREDICATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ DateTime => :date_time?, FalseClass => :false?, Integer => :int?, NilClass => :nil?, String => :str?, TrueClass => :true? }.freeze
- REDUCED_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ %i[true? false?] => :bool? }.freeze
Instance Attribute Summary collapse
- #compiler ⇒ Compiler readonly private
Instance Method Summary collapse
-
#[](type) ⇒ Symbol
private
Infer predicate identifier from the provided type.
-
#initialize(registry) ⇒ PredicateInferrer
constructor
private
A new instance of PredicateInferrer.
Constructor Details
#initialize(registry) ⇒ PredicateInferrer
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 PredicateInferrer.
120 121 122 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 120 def initialize(registry) @compiler = Compiler.new(registry) end |
Instance Attribute Details
#compiler ⇒ Compiler (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.
117 118 119 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 117 def compiler @compiler end |
Instance Method Details
#[](type) ⇒ Symbol
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 predicate identifier from the provided type
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 129 def [](type) self.class.fetch_or_store(type.hash) do predicates = compiler.visit(type.to_ast) if predicates.is_a?(Hash) predicates else Array(REDUCED_TYPES[predicates] || predicates).flatten end end end |