Class: Dry::Schema::Macros::Key
- Defined in:
- lib/dry/schema/macros/key.rb
Overview
Base macro for specifying rules applied to a value found under a key
Instance Attribute Summary collapse
- #filter_schema_dsl ⇒ Schema::DSL readonly private
Attributes inherited from DSL
#chain, #predicate_inferrer, #primitive_inferrer
Instance Method Summary collapse
-
#filter ⇒ Macros::Key
Specify predicates that should be applied before coercion.
- #to_ast ⇒ Object private
-
#to_rule ⇒ Dry::Logic::Rule
private
Coerce macro to a rule.
Methods inherited from DSL
#array, #custom_type?, #each, #filled, #hash, #maybe, #schema, #type, #value
Methods inherited from Core
Instance Attribute Details
#filter_schema_dsl ⇒ Schema::DSL (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.
13 |
# File 'lib/dry/schema/macros/key.rb', line 13 option :filter_schema_dsl, default: proc { schema_dsl&.filter_schema_dsl } |
Instance Method Details
#filter ⇒ Macros::Key
Specify predicates that should be applied before coercion
25 26 27 28 |
# File 'lib/dry/schema/macros/key.rb', line 25 def filter(...) (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(...) self end |
#to_ast ⇒ 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.
44 45 46 |
# File 'lib/dry/schema/macros/key.rb', line 44 def to_ast [:predicate, [:key?, [[:name, name], [:input, Undefined]]]] end |
#to_rule ⇒ Dry::Logic::Rule
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.
Coerce macro to a rule
35 36 37 38 39 40 41 |
# File 'lib/dry/schema/macros/key.rb', line 35 def to_rule if trace.captures.empty? super else [super, trace.to_rule(name)].reduce(operation) end end |