class OpenApi::Rswag::Ui::Middleware
Public Class Methods
new(app, config)
click to toggle source
Calls superclass method
# File lib/open_api/rswag/ui/middleware.rb, line 6 def initialize(app, config) @config = config super(app, urls: [ '' ], root: config.assets_root ) end
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# File lib/open_api/rswag/ui/middleware.rb, line 11 def call(env) if base_path?(env) redirect_uri = env['SCRIPT_NAME'].chomp('/') + '/index.html' return [ 301, { 'Location' => redirect_uri }, [ ] ] end if index_path?(env) return [ 200, { 'Content-Type' => 'text/html' }, [ render_template ] ] end super end
Private Instance Methods
base_path?(env)
click to toggle source
# File lib/open_api/rswag/ui/middleware.rb, line 26 def base_path?(env) env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/" end
index_path?(env)
click to toggle source
# File lib/open_api/rswag/ui/middleware.rb, line 30 def index_path?(env) env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/index.html" end
render_template()
click to toggle source
# File lib/open_api/rswag/ui/middleware.rb, line 34 def render_template file = File.new(template_filename) template = ERB.new(file.read) template.result(@config.get_binding) end
template_filename()
click to toggle source
# File lib/open_api/rswag/ui/middleware.rb, line 40 def template_filename @config.template_locations.find { |filename| File.exists?(filename) } end