Class: Goliath::Rack::Validation::RequestMethod
- Inherits:
-
Object
- Object
- Goliath::Rack::Validation::RequestMethod
- Defined in:
- lib/goliath/rack/validation/request_method.rb
Overview
A middleware to validate that the request had a given HTTP method.
Constant Summary
- ERROR =
'Invalid request method'
Instance Attribute Summary (collapse)
-
- (Object) methods
readonly
Returns the value of attribute methods.
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (Goliath::Rack::Validation::RequestMethod) initialize(app, methods = [])
constructor
Called by the framework to create the Goliath::Rack::Validation::RequestMethod validator.
Constructor Details
- (Goliath::Rack::Validation::RequestMethod) initialize(app, methods = [])
Called by the framework to create the Goliath::Rack::Validation::RequestMethod validator
21 22 23 24 |
# File 'lib/goliath/rack/validation/request_method.rb', line 21 def initialize(app, methods = []) @app = app @methods = methods end |
Instance Attribute Details
- (Object) methods (readonly)
Returns the value of attribute methods
12 13 14 |
# File 'lib/goliath/rack/validation/request_method.rb', line 12 def methods @methods end |
Instance Method Details
- (Object) call(env)
26 27 28 29 |
# File 'lib/goliath/rack/validation/request_method.rb', line 26 def call(env) raise Goliath::Validation::Error.new(400, ERROR) unless methods.include?(env['REQUEST_METHOD']) @app.call(env) end |