class Rack::ReadOnly

Constants

ALL_METHODS
READ_METHODS
VERSION
WRITE_METHODS

Attributes

app[R]
options[R]

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/rack/read_only.rb, line 11
def initialize(app, options = {})
  @app = app
  @options = options
end

Public Instance Methods

active?() click to toggle source
# File lib/rack/read_only.rb, line 16
def active?
  options[:active]
end
call(env) click to toggle source
# 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() click to toggle source
# File lib/rack/read_only.rb, line 20
def response_body
  options[:response_body]
end
response_headers() click to toggle source
# File lib/rack/read_only.rb, line 28
def response_headers
  options.fetch(:response_headers, {
    'Content-Type' => 'application/json'
  })
end
response_status() click to toggle source
# File lib/rack/read_only.rb, line 24
def response_status
  options.fetch(:response_status, 503)
end