Class: Waitress::LibraryHandler
- Defined in:
- lib/waitress/handlers/libhandler.rb
Overview
The LibraryHandler is used to handle requests to the VHost regarding the libraries to be loaded by other Handlers and .wrb files. This will take any requests to /libraries (or whatever the user has set it to) to load libraries
Instance Attribute Summary collapse
-
#priority ⇒ Object
Returns the value of attribute priority.
Instance Method Summary collapse
- #dirType(k) ⇒ Object
-
#initialize(libraries, libdir, liburi, vhost) ⇒ LibraryHandler
constructor
A new instance of LibraryHandler.
- #respond?(request, vhost) ⇒ Boolean
- #serve(request, response, client, vhost) ⇒ Object
Methods inherited from Handler
Constructor Details
#initialize(libraries, libdir, liburi, vhost) ⇒ LibraryHandler
Returns a new instance of LibraryHandler.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/waitress/handlers/libhandler.rb', line 10 def initialize libraries, libdir, liburi, vhost @priority = 150 @vhost = vhost @libraries, @libdir, @liburi = libraries, File.(libdir), liburi FileUtils.mkdir_p(@libdir) unless File.exist?(@libdir) @libraries.each do |name, lib| l = {} d = dirType(lib[:bindtype]) matches = Dir["#{d}/**/*.#{lib[:bindtype].to_s}"].select { |x| (x =~ lib[:pattern]) != nil } if matches.length > 0 l[:file] = matches[0] l[:type] = lib[:bindtype] else l = nil end @libraries[name] = l end [:css, :js].each do |k| d = dirType k FileUtils.mkdir_p(d) unless File.exist?(d) Dir["#{d}/**/*.#{k.to_s}"].each do |fl| @libraries[File.basename(fl).to_sym] = { :file => fl, :type => k } end end end |
Instance Attribute Details
#priority ⇒ Object
Returns the value of attribute priority.
8 9 10 |
# File 'lib/waitress/handlers/libhandler.rb', line 8 def priority @priority end |
Instance Method Details
#dirType(k) ⇒ Object
39 40 41 |
# File 'lib/waitress/handlers/libhandler.rb', line 39 def dirType k File.join(@libdir, k.to_s) end |
#respond?(request, vhost) ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/waitress/handlers/libhandler.rb', line 43 def respond? request, vhost path = request.path return false unless path.start_with?("/#{@liburi}/") name = path.sub("/#{@liburi}/", "").to_sym @libraries.include?(name) end |
#serve(request, response, client, vhost) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/waitress/handlers/libhandler.rb', line 50 def serve request, response, client, vhost path = request.path name = path.sub("/#{@liburi}/", "").to_sym lib = @libraries[name] Waitress::Chef.serve_file request, response, client, vhost, lib[:file] end |