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 collapse
- ERROR =
'Invalid request method'
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, methods = []) ⇒ Goliath::Rack::Validation::RequestMethod
constructor
Called by the framework to create the Goliath::Rack::Validation::RequestMethod validator.
Constructor Details
#initialize(app, methods = []) ⇒ Goliath::Rack::Validation::RequestMethod
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
#methods ⇒ Object (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
#call(env) ⇒ Object
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 |