Class: Goliath::Rack::Validation::RequestMethod
- Inherits:
-
Object
- Object
- Goliath::Rack::Validation::RequestMethod
- Includes:
- Goliath::Rack::Validator
- 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.
Methods included from Goliath::Rack::Validator
Constructor Details
#initialize(app, methods = []) ⇒ Goliath::Rack::Validation::RequestMethod
Called by the framework to create the Goliath::Rack::Validation::RequestMethod validator
22 23 24 25 |
# File 'lib/goliath/rack/validation/request_method.rb', line 22 def initialize(app, methods = []) @app = app @methods = Array(methods) end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
13 14 15 |
# File 'lib/goliath/rack/validation/request_method.rb', line 13 def methods @methods end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 |
# File 'lib/goliath/rack/validation/request_method.rb', line 27 def call(env) return validation_error(405, ERROR, "Allow" => methods.map{|m| m.to_s.upcase}.join(', ')) unless methods.include?(env['REQUEST_METHOD']) @app.call(env) end |