Class: GraphdocRuby::Static
- Inherits:
-
Object
- Object
- GraphdocRuby::Static
- Defined in:
- lib/graphdoc-ruby/static.rb
Instance Method Summary collapse
-
#initialize(root, headers: {}) ⇒ Static
constructor
A new instance of Static.
- #match?(path) ⇒ Boolean
- #serve(request) ⇒ Object
Constructor Details
Instance Method Details
#match?(path) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphdoc-ruby/static.rb', line 13 def match?(path) path = ::Rack::Utils.unescape_path(path) return false unless ::Rack::Utils.valid_path? path path = ::Rack::Utils.clean_path_info(path) candidate_paths = [path, "#{path}.html", "#{path}/index.html"] match = candidate_paths.detect do |candidate_path| absolute_path = File.join(@root, candidate_path.dup.force_encoding(Encoding::UTF_8)) begin File.file?(absolute_path) && File.readable?(absolute_path) rescue SystemCallError false end end ::Rack::Utils.escape_path(match) if match end |
#serve(request) ⇒ Object
33 34 35 |
# File 'lib/graphdoc-ruby/static.rb', line 33 def serve(request) @file_server.call(request.env) end |