Sha256: 8970a972e99691c5070cf0198e60d881d328505900837c28216aeb320237c9d8

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 Bytes

Contents

require "rack/read_only/version"

module Rack
  class ReadOnly
    attr_reader :app, :options

    def initialize(app, options = {})
      @app = app
      @options = options
    end

    def active?
      options[:active]
    end

    def response_body
      options[:response_body]
    end

    def response_status
      options.fetch(:response_status, 503)
    end

    def response_headers
      options.fetch(:response_headers, {
        'Content-Type' => 'application/json'
      })
    end

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-read_only-1.0.0 lib/rack/read_only.rb