Class: Swagui::AssetHandler
- Inherits:
-
Object
- Object
- Swagui::AssetHandler
- Defined in:
- lib/swagui/asset_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #handles?(env) ⇒ Boolean
-
#initialize(path) ⇒ AssetHandler
constructor
A new instance of AssetHandler.
Constructor Details
#initialize(path) ⇒ AssetHandler
Returns a new instance of AssetHandler.
4 5 6 7 8 9 10 11 |
# File 'lib/swagui/asset_handler.rb', line 4 def initialize(path) @url_regex = Regexp.union(Regexp.new("^\/swagger-ui"), Regexp.new("^#{path}\/?$")) swagger_ui_dir = File.('../../swagger-ui', File.dirname(__FILE__)) raise "swagger ui assets directory #{swagger_ui_dir} does not exist" unless File.directory?(swagger_ui_dir) @asset_file_server = Rack::File.new(swagger_ui_dir) end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 |
# File 'lib/swagui/asset_handler.rb', line 17 def call(env) env["PATH_INFO"] = env["PATH_INFO"].gsub(@url_regex, '') env["PATH_INFO"] = 'index.html' if env["PATH_INFO"] == '' @asset_file_server.call(env) end |
#handles?(env) ⇒ Boolean
13 14 15 |
# File 'lib/swagui/asset_handler.rb', line 13 def handles?(env) @url_regex === env["PATH_INFO"] end |