Class: Interceptors::ValidationInterceptor

Inherits:
Interceptor
  • Object
show all
Defined in:
lib/interceptors/validation_interceptor.rb

Instance Method Summary collapse

Methods inherited from Interceptor

#after, #around

Constructor Details

#initialize(&block) ⇒ ValidationInterceptor

Returns a new instance of ValidationInterceptor.

Raises:

  • (ArgumentError)


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

Raises:



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