Class: Rack::StaticBuilder::RequestPathQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/static-builder.rb

Instance Method Summary collapse

Constructor Details

#initializeRequestPathQueue

Returns a new instance of RequestPathQueue.



14
15
16
17
18
# File 'lib/rack/static-builder.rb', line 14

def initialize
  @active = nil
  @queue = ['/']
  @seen = {}
end

Instance Method Details

#drainObject



34
35
36
37
38
# File 'lib/rack/static-builder.rb', line 34

def drain
  while path = @queue.shift
    @seen[path] ||= (yield(path); true)
  end
end

#enqueue(url) ⇒ Object Also known as: <<



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/static-builder.rb', line 20

def enqueue(url)
  path = URI.parse(url).path

  # discard URNs like data: and magnet:
  return false unless path

  if path[0] != '/'
    path = URI.parse( (@active || '/').sub(/\/[^\/]*$/, '') + '/' + path ).path
  end

  @queue << path
end