module Performify::Validation::InstanceMethods
Public Instance Methods
errors()
click to toggle source
# File lib/performify/validation.rb, line 46 def errors @errors ||= {} end
errors!(new_errors)
click to toggle source
# File lib/performify/validation.rb, line 38 def errors!(new_errors) raise ArgumentError, 'Errors should be a hash' if new_errors.nil? || !new_errors.respond_to?(:to_h) new_errors.to_h.each do |key, value| errors[key] = errors.key?(key) ? [errors[key]].flatten(1) + [value].flatten(1) : value end end
errors?()
click to toggle source
# File lib/performify/validation.rb, line 50 def errors? errors.any? end
schema()
click to toggle source
# File lib/performify/validation.rb, line 21 def schema self.class.schema end
validate()
click to toggle source
# File lib/performify/validation.rb, line 25 def validate return args if schema.nil? result = schema.call(args) if result.success? @inputs = result.output else errors!(result.errors) end result.output end