Class: Dry::Schema::PredicateInferrer::Compiler Private
- Inherits:
-
Object
- Object
- Dry::Schema::PredicateInferrer::Compiler
- 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.
Compiler reduces type AST into a list of predicates
Instance Attribute Summary collapse
- #registry ⇒ PredicateRegistry readonly private
Instance Method Summary collapse
- #infer_predicate(type) ⇒ Object private
-
#initialize(registry) ⇒ Compiler
constructor
private
A new instance of Compiler.
- #visit(node) ⇒ Object private
- #visit_any(_) ⇒ Object private
- #visit_array(_) ⇒ Object private
- #visit_constrained(node) ⇒ Object private
- #visit_constructor(node) ⇒ Object private
- #visit_enum(node) ⇒ Object private
- #visit_hash(_) ⇒ Object private
- #visit_lax(node) ⇒ Object private
- #visit_nominal(node) ⇒ Object private
- #visit_sum(node) ⇒ Object private
Constructor Details
#initialize(registry) ⇒ Compiler
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 Compiler.
36 37 38 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 36 def initialize(registry) @registry = registry end |
Instance Attribute Details
#registry ⇒ PredicateRegistry (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.
33 34 35 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 33 def registry @registry end |
Instance Method Details
#infer_predicate(type) ⇒ Object
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.
41 42 43 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 41 def infer_predicate(type) TYPE_TO_PREDICATE.fetch(type) { :"#{type.name.split('::').last.downcase}?" } end |
#visit(node) ⇒ Object
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.
46 47 48 49 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 46 def visit(node) meth, rest = node public_send(:"visit_#{meth}", rest) end |
#visit_any(_) ⇒ Object
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.
110 111 112 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 110 def visit_any(_) nil end |
#visit_array(_) ⇒ Object
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.
69 70 71 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 69 def visit_array(_) :array? end |
#visit_constrained(node) ⇒ Object
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.
104 105 106 107 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 104 def visit_constrained(node) other, * = node visit(other) end |
#visit_constructor(node) ⇒ Object
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.
79 80 81 82 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 79 def visit_constructor(node) other, * = node visit(other) end |
#visit_enum(node) ⇒ Object
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.
85 86 87 88 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 85 def visit_enum(node) other, * = node visit(other) end |
#visit_hash(_) ⇒ Object
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.
64 65 66 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 64 def visit_hash(_) :hash? end |
#visit_lax(node) ⇒ Object
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.
74 75 76 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 74 def visit_lax(node) visit(node) end |
#visit_nominal(node) ⇒ Object
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.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 52 def visit_nominal(node) type = node[0] predicate = infer_predicate(type) if registry.key?(predicate) predicate else { type?: type } end end |
#visit_sum(node) ⇒ Object
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.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dry/schema/predicate_inferrer.rb', line 91 def visit_sum(node) left, right = node predicates = [visit(left), visit(right)] if predicates.first == :nil? predicates[1..predicates.size - 1] else predicates end end |