Class: ClientSideValidations::Middleware::Validators

Inherits:
Object
  • Object
show all
Defined in:
lib/client_side_validations/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Validators

Returns a new instance of Validators.



9
10
11
# File 'lib/client_side_validations/middleware.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/client_side_validations/middleware.rb', line 13

def call(env)
  if matches = /^\/validators\/(\w+)$/.match(env['PATH_INFO'])
    if ClientSideValidations::Config.disabled_validators.include?(matches[1].to_sym)
      [500, {'Content-Type' => 'application/json', 'Content-Length' => '0'}, ['']]
    else
      "::ClientSideValidations::Middleware::#{matches[1].camelize}".constantize.new(env).response
    end
  else
    @app.call(env)
  end
end