class Dry::Schema::Macros::Key
Base macro for specifying rules applied to a value found under a key
@api public
Public Instance Methods
filter(...)
click to toggle source
Specify predicates that should be applied before coercion
@example check format before coercing to a date
required(:publish_date).filter(format?: /\d{4}-\d{2}-\d{2}).value(:date)
@see Macros::Key#value
@return [Macros::Key]
@api public
# File lib/dry/schema/macros/key.rb, line 29 def filter(...) (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(...) self end
to_ast()
click to toggle source
@api private
# File lib/dry/schema/macros/key.rb, line 49 def to_ast [:predicate, [:key?, [[:name, name], [:input, Undefined]]]] end
to_rule()
click to toggle source
Coerce macro to a rule
@return [Dry::Logic::Rule]
@api private
Calls superclass method
Dry::Schema::Macros::Core#to_rule
# File lib/dry/schema/macros/key.rb, line 40 def to_rule if trace.captures.empty? super else [super, trace.to_rule(name)].reduce(operation) end end