Class: SteelWheel::Handler::Validator
- Inherits:
-
Object
- Object
- SteelWheel::Handler::Validator
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/steel_wheel/handler.rb
Overview
Runs validation on objects
Instance Attribute Summary collapse
-
#http_status ⇒ Object
Returns the value of attribute http_status.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#http_status ⇒ Object
Returns the value of attribute http_status.
25 26 27 |
# File 'lib/steel_wheel/handler.rb', line 25 def http_status @http_status end |
Class Method Details
.run(flow) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/steel_wheel/handler.rb', line 27 def self.run(flow) validator = new [flow.params, flow.query, flow.command].each do |obj| break if validator.errors.any? validator.validate(obj) end flow.status = validator.http_status || :ok flow.errors.merge!(validator.errors) end |
Instance Method Details
#validate(object) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/steel_wheel/handler.rb', line 38 def validate(object) return if object.valid? self.http_status ||= object.http_status errors.merge!(object.errors) if errors.empty? end |