Module: Performify::Validation::InstanceMethods
- Defined in:
- lib/performify/validation.rb
Instance Method Summary collapse
- #errors ⇒ Object
- #errors!(new_errors) ⇒ Object
- #errors? ⇒ Boolean
- #schema ⇒ Object
- #validate ⇒ Object
Instance Method Details
#errors ⇒ Object
39 40 41 |
# File 'lib/performify/validation.rb', line 39 def errors @errors ||= {} end |
#errors!(new_errors) ⇒ Object
34 35 36 37 |
# File 'lib/performify/validation.rb', line 34 def errors!(new_errors) raise ArgumentError, 'Errors should be a hash' if new_errors.nil? || !new_errors.respond_to?(:to_h) errors.merge!(new_errors.to_h) end |
#errors? ⇒ Boolean
43 44 45 |
# File 'lib/performify/validation.rb', line 43 def errors? errors.any? end |
#schema ⇒ Object
23 24 25 |
# File 'lib/performify/validation.rb', line 23 def schema self.class.schema end |
#validate ⇒ Object
27 28 29 30 31 32 |
# File 'lib/performify/validation.rb', line 27 def validate return args if schema.nil? result = schema.call(args) errors!(result.errors) unless result.success? result.output end |