Class: Dry::Schema::Macros::DSL
- Includes:
- Logic::Operators
- Defined in:
- lib/dry/schema/macros/dsl.rb
Overview
Macro specialization used within the DSL
Instance Attribute Summary collapse
-
#chain ⇒ Boolean
readonly
private
Indicate if the macro should append its rules to the provided trace.
-
#predicate_inferrer ⇒ PredicateInferrer
readonly
private
PredicateInferrer is used to infer predicate type-check from a type spec.
-
#primitive_inferrer ⇒ PrimitiveInferrer
readonly
private
PrimitiveInferrer used to get a list of primitive classes from configured type.
Instance Method Summary collapse
-
#array(*args, &block) ⇒ Macros::Core
Like ‘each` but sets `array?` type-check.
-
#each(*args, &block) ⇒ Macros::Core
Specify predicates that should be applied to each element of an array.
-
#filled(*args, **opts, &block) ⇒ Macros::Core
Prepends ‘:filled?` predicate.
-
#hash(*args, &block) ⇒ Object
Specify a nested hash with enforced ‘hash?` type-check.
-
#schema(*args, &block) ⇒ Macros::Core
Specify a nested hash without enforced ‘hash?` type-check.
-
#type(spec) ⇒ Macros::Key
Set type spec.
-
#value(*predicates, **predicate_opts) ⇒ Macros::Core
Set predicates without and with arguments.
Methods inherited from Core
#new, #operation, #to_ast, #to_rule
Instance Attribute Details
#chain ⇒ Boolean (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.
Indicate if the macro should append its rules to the provided trace
23 |
# File 'lib/dry/schema/macros/dsl.rb', line 23 option :chain, default: -> { true } |
#predicate_inferrer ⇒ PredicateInferrer (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.
PredicateInferrer is used to infer predicate type-check from a type spec
29 |
# File 'lib/dry/schema/macros/dsl.rb', line 29 option :predicate_inferrer, default: proc { PredicateInferrer.new(compiler.predicates) } |
#primitive_inferrer ⇒ PrimitiveInferrer (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.
PrimitiveInferrer used to get a list of primitive classes from configured type
35 |
# File 'lib/dry/schema/macros/dsl.rb', line 35 option :primitive_inferrer, default: proc { PrimitiveInferrer.new } |
Instance Method Details
#array(*args, &block) ⇒ Macros::Core
Like ‘each` but sets `array?` type-check
151 152 153 154 155 |
# File 'lib/dry/schema/macros/dsl.rb', line 151 def array(*args, &block) append_macro(Macros::Array) do |macro| macro.value(*args, &block) end end |
#each(*args, &block) ⇒ Macros::Core
Specify predicates that should be applied to each element of an array
This is a simpler building block than ‘array` macro, use it when you want to provide `array?` type-check with other rules manually.
132 133 134 135 136 |
# File 'lib/dry/schema/macros/dsl.rb', line 132 def each(*args, &block) append_macro(Macros::Each) do |macro| macro.value(*args, &block) end end |
#filled(*args, **opts, &block) ⇒ Macros::Core
Prepends ‘:filled?` predicate
75 76 77 78 79 |
# File 'lib/dry/schema/macros/dsl.rb', line 75 def filled(*args, **opts, &block) append_macro(Macros::Filled) do |macro| macro.call(*args, **opts, &block) end end |
#hash(*args, &block) ⇒ Object
Specify a nested hash with enforced ‘hash?` type-check
109 110 111 112 113 |
# File 'lib/dry/schema/macros/dsl.rb', line 109 def hash(*args, &block) append_macro(Macros::Hash) do |macro| macro.call(*args, &block) end end |
#schema(*args, &block) ⇒ Macros::Core
Specify a nested hash without enforced ‘hash?` type-check
This is a simpler building block than ‘hash` macro, use it when you want to provide `hash?` type-check with other rules manually.
95 96 97 98 99 |
# File 'lib/dry/schema/macros/dsl.rb', line 95 def schema(*args, &block) append_macro(Macros::Schema) do |macro| macro.call(*args, &block) end end |
#type(spec) ⇒ Macros::Key
Set type spec
167 168 169 170 |
# File 'lib/dry/schema/macros/dsl.rb', line 167 def type(spec) schema_dsl.set_type(name, spec) self end |
#value(*predicates, **predicate_opts) ⇒ Macros::Core
58 59 60 61 62 |
# File 'lib/dry/schema/macros/dsl.rb', line 58 def value(*predicates, **opts, &block) append_macro(Macros::Value) do |macro| macro.call(*predicates, **opts, &block) end end |