Module: CMDx::Validators::Validate
Overview
Invokes an inline ‘:validate` handler. Used by #validate for each handler passed under the `:validate` option.
Instance Method Summary collapse
-
#call(task, value, handler) ⇒ Validators::Failure, ...
Handler’s return value.
Instance Method Details
#call(task, value, handler) ⇒ Validators::Failure, ...
Note:
Symbol handlers are dispatched via ‘send` so private helpers on the task are reachable. Handlers are baked into class definitions; never derive them from untrusted input.
Returns handler’s return value.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cmdx/validators/validate.rb', line 19 def call(task, value, handler) case handler when Symbol task.send(handler, value) when Proc task.instance_exec(value, &handler) else return handler.call(value, task) if handler.respond_to?(:call) raise ArgumentError, <<~MSG.chomp validate handler must be a Symbol, Proc, or respond to #call (got #{handler.class}). See https://drexed.github.io/cmdx/inputs/validations/#inline-validate-callable MSG end end |