Class: Interceptors::ValidationInterceptor
- Inherits:
-
Interceptor
- Object
- Interceptor
- Interceptors::ValidationInterceptor
- Defined in:
- lib/interceptors/validation_interceptor.rb
Instance Method Summary collapse
- #before(ctx) ⇒ Object
-
#initialize(&block) ⇒ ValidationInterceptor
constructor
A new instance of ValidationInterceptor.
Methods inherited from Interceptor
Constructor Details
#initialize(&block) ⇒ ValidationInterceptor
Returns a new instance of ValidationInterceptor.
5 6 7 8 9 |
# File 'lib/interceptors/validation_interceptor.rb', line 5 def initialize(&block) raise ArgumentError, "validation block is required" unless block @validator = block end |
Instance Method Details
#before(ctx) ⇒ Object
11 12 13 14 |
# File 'lib/interceptors/validation_interceptor.rb', line 11 def before(ctx) errors = normalize_errors(@validator.call(ctx)) raise ValidationError.new(errors) if errors.any? end |