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
-
#filled(*args, **opts, &block) ⇒ Macros::Key
Set type specification and predicates for a filled value.
-
#filter(*args, &block) ⇒ Macros::Key
Specify predicates that should be applied before coercion.
-
#maybe(*args, **opts, &block) ⇒ Macros::Key
Set type specification and predicates for a maybe value.
- #to_ast ⇒ Object private
-
#to_rule ⇒ Dry::Logic::Rule
private
Coerce macro to a rule.
-
#value(type_spec, *predicates, **predicate_opts) ⇒ Macros::Key
Set type specification and predicates.
Methods inherited from DSL
#array, #each, #hash, #schema, #type
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.
18 |
# File 'lib/dry/schema/macros/key.rb', line 18 option :filter_schema_dsl, default: proc { schema_dsl&.filter_schema_dsl } |
Instance Method Details
#filled(*args, **opts, &block) ⇒ Macros::Key
Set type specification and predicates for a filled value
72 73 74 75 76 |
# File 'lib/dry/schema/macros/key.rb', line 72 def filled(*args, **opts, &block) extract_type_spec(*args) do |*predicates, type_spec:| super(*predicates, type_spec: type_spec, **opts, &block) end end |
#filter(*args, &block) ⇒ Macros::Key
Specify predicates that should be applied before coercion
30 31 32 33 |
# File 'lib/dry/schema/macros/key.rb', line 30 def filter(*args, &block) (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(*args, &block) self end |
#maybe(*args, **opts, &block) ⇒ Macros::Key
Set type specification and predicates for a maybe value
88 89 90 91 92 93 94 |
# File 'lib/dry/schema/macros/key.rb', line 88 def maybe(*args, **opts, &block) extract_type_spec(*args, nullable: true) do |*predicates, type_spec:| append_macro(Macros::Maybe) do |macro| macro.call(*predicates, **opts, &block) end end 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.
110 111 112 |
# File 'lib/dry/schema/macros/key.rb', line 110 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
101 102 103 104 105 106 107 |
# File 'lib/dry/schema/macros/key.rb', line 101 def to_rule if trace.captures.empty? super else [super, trace.to_rule(name)].reduce(operation) end end |
#value(type_spec, *predicates, **predicate_opts) ⇒ Macros::Key
56 57 58 59 60 |
# File 'lib/dry/schema/macros/key.rb', line 56 def value(*args, **opts, &block) extract_type_spec(*args) do |*predicates, type_spec:| super(*predicates, type_spec: type_spec, **opts, &block) end end |