class Dry::Schema::Macros::DSL
@api public
Macro specialization used within the DSL
def append_macro(macro_type)
- Api: - private
def append_macro(macro_type) macro = macro_type.new(schema_dsl: schema_dsl, name: name) yield(macro) if chain trace << macro self else macro end end
def array(*args, &block)
- Api: - public
Returns:
-
(Macros::Core)
-
Other tags:
- Example: a list of hashes -
Example: a list of strings -
def array(*args, &block) append_macro(Macros::Array) do |macro| macro.value(*args, &block) end end
def each(*args, &block)
- Api: - public
Returns:
-
(Macros::Core)
-
Other tags:
- Example: a list of hashes -
Example: a list of strings -
def each(*args, &block) append_macro(Macros::Each) do |macro| macro.value(*args, &block) end end
def extract_type_spec(*args, nullable: false, set_type: true)
- Api: - private
def extract_type_spec(*args, nullable: false, set_type: true) type_spec = args[0] is_type_spec = type_spec.is_a?(Dry::Schema::Processor) || type_spec.is_a?(Symbol) && type_spec.to_s.end_with?(QUESTION_MARK) type_spec = nil if is_type_spec predicates = Array(type_spec ? args[1..-1] : args) if type_spec resolved_type = resolve_type(type_spec, nullable) type(resolved_type) if set_type type_predicates = predicate_inferrer[resolved_type] predicates.replace(type_predicates + predicates) unless type_predicates.empty? return self if predicates.empty? end yield(*predicates, type_spec: type_spec) end
def filled(*args, **opts, &block)
- Api: - public
Returns:
-
(Macros::Core)
-
Other tags:
- Example: with a type spec and a predicate -
Example: with a type spec -
def filled(*args, **opts, &block) append_macro(Macros::Filled) do |macro| macro.call(*args, **opts, &block) end end
def hash(*args, &block)
- Api: - public
def hash(*args, &block) append_macro(Macros::Hash) do |macro| macro.call(*args, &block) end end
def resolve_type(type_spec, nullable)
- Api: - private
def resolve_type(type_spec, nullable) resolved = schema_dsl.resolve_type(type_spec) if type_spec.is_a?(::Array) || !nullable || resolved.optional? resolved else schema_dsl.resolve_type([:nil, resolved]) end end
def schema(*args, &block)
- Api: - public
Returns:
-
(Macros::Core)
-
def schema(*args, &block) append_macro(Macros::Schema) do |macro| macro.call(*args, &block) end end
def type(spec)
- Api: - public
Returns:
-
(Macros::Key)
-
Parameters:
-
spec
(Symbol, Array, Dry::Types::Type
) --
def type(spec) schema_dsl.set_type(name, spec) self end
def value(*predicates, **opts, &block)
- Api: - public
Returns:
-
(Macros::Core)
-
Other tags:
- Example: with a block -
Example: with a predicate with and without arguments -
Example: with a predicate with arguments -
Example: with a predicate -
Parameters:
-
predicate_opts
(Hash
) -- -
predicates
(Array
) --
Overloads:
-
value(*predicates, **predicate_opts)
def value(*predicates, **opts, &block) append_macro(Macros::Value) do |macro| macro.call(*predicates, **opts, &block) end end