Class: Rack::ReadOnly
- Inherits:
-
Object
- Object
- Rack::ReadOnly
- Defined in:
- lib/rack/read_only.rb,
lib/rack/read_only/version.rb
Constant Summary collapse
- READ_METHODS =
%w(HEAD GET OPTIONS)
- WRITE_METHODS =
%w(POST PUT DELETE PATCH)
- ALL_METHODS =
READ_METHODS + WRITE_METHODS
- VERSION =
"2.0.0"
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ReadOnly
constructor
A new instance of ReadOnly.
- #response_body ⇒ Object
- #response_headers ⇒ Object
- #response_status ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ ReadOnly
Returns a new instance of ReadOnly.
11 12 13 14 |
# File 'lib/rack/read_only.rb', line 11 def initialize(app, = {}) @app = app @options = end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
9 10 11 |
# File 'lib/rack/read_only.rb', line 9 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/rack/read_only.rb', line 9 def @options end |
Instance Method Details
#active? ⇒ Boolean
16 17 18 |
# File 'lib/rack/read_only.rb', line 16 def active? [:active] end |
#call(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rack/read_only.rb', line 34 def call(env) if active? && WRITE_METHODS.include?(env['REQUEST_METHOD']) response = Rack::Response.new( response_body, response_status, response_headers ) return response end app.call(env) end |
#response_body ⇒ Object
20 21 22 |
# File 'lib/rack/read_only.rb', line 20 def response_body [:response_body] end |
#response_headers ⇒ Object
28 29 30 31 32 |
# File 'lib/rack/read_only.rb', line 28 def response_headers .fetch(:response_headers, { 'Content-Type' => 'application/json' }) end |
#response_status ⇒ Object
24 25 26 |
# File 'lib/rack/read_only.rb', line 24 def response_status .fetch(:response_status, 503) end |