class Angband::Documentation

Public Class Methods

new(app) { |self| ... } click to toggle source
# File lib/angband/documentation.rb, line 7
def initialize(app)
  @app = app
  yield self if block_given?
end

Public Instance Methods

call(env) click to toggle source
# File lib/angband/documentation.rb, line 12
def call(env)
  response = Rack::AcceptHeaders.new(@app).call(env)

  if options_request?(env) && successful?(response) && !cross_origin_request?(env)
    features  = Angband::GherkinFinder.new(@files).call(env['PATH_INFO'])
    formatter = Angband::Formatter.new(env['rack-accept_headers.request'])

    headers, content = formatter.call(features)
    response[1].merge!(headers)
    response[2] = [content]
  end

  response
end
configure(files) click to toggle source
# File lib/angband/documentation.rb, line 27
def configure(files)
  @files = files
end

Private Instance Methods

cross_origin_request?(env) click to toggle source
# File lib/angband/documentation.rb, line 33
def cross_origin_request?(env)
  env['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] || env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
end
options_request?(env) click to toggle source
# File lib/angband/documentation.rb, line 37
def options_request?(env)
  'OPTIONS' == env['REQUEST_METHOD']
end
successful?(response) click to toggle source
# File lib/angband/documentation.rb, line 41
def successful?(response)
  200 == response[0].to_i
end