Class: Superconductor::Documentation

Inherits:
Object
  • Object
show all
Includes:
Rack::Utils
Defined in:
lib/superconductor/documentation.rb

Overview

Superconductor Documentation Service

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, index: "index.html") ⇒ Documentation

Returns a new instance of Documentation.



12
13
14
15
# File 'lib/superconductor/documentation.rb', line 12

def initialize(path: nil, index: "index.html")
  @path ||= File.join(Dir.getwd, 'doc')
  @index = index
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/superconductor/documentation.rb', line 17

def call(env)
  path = env["PATH_INFO"][1..-1]
  file = path == "" ? @index : path
  headers = HeaderHash.new({
    'Content-Type' => content_type(file)
  })
  body = [open(File.join(@path, file)).read]
  status = 200
  [status, headers, body]
end