Class: Rack::ESI
- Inherits:
-
Object
- Object
- Rack::ESI
- Defined in:
- lib/rack-esi/threaded.rb,
lib/rack-esi/version.rb,
lib/rack-esi/processor.rb,
lib/rack-esi.rb
Overview
require 'timeout'
Defined Under Namespace
Classes: Finisher, Processor, Worker
Constant Summary
- VERSION =
"0.2.0"
Instance Attribute Summary (collapse)
-
- (Object) parser
readonly
Returns the value of attribute parser.
-
- (Object) serializer
readonly
Returns the value of attribute serializer.
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (ESI) initialize(app, options = {})
constructor
A new instance of ESI.
- - (Object) queue(&block)
Constructor Details
- (ESI) initialize(app, options = {})
A new instance of ESI
10 11 12 13 14 15 16 17 18 |
# File 'lib/rack-esi.rb', line 10 def initialize(app, = {}) @app = app @parser = .fetch :parser, Nokogiri::XML::Document @serializer = .fetch :serializer, :to_xhtml @skip = [:skip] @poolsize = .fetch :poolsize, 4 @processor = @poolsize == 1 ? Processor::Linear : Processor::Threaded end |
Instance Attribute Details
- (Object) parser (readonly)
Returns the value of attribute parser
31 32 33 |
# File 'lib/rack-esi.rb', line 31 def parser @parser end |
- (Object) serializer (readonly)
Returns the value of attribute serializer
31 32 33 |
# File 'lib/rack-esi.rb', line 31 def serializer @serializer end |
Instance Method Details
- (Object) call(env)
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rack-esi.rb', line 33 def call(env) return @app.call(env) if @skip === env['PATH_INFO'] status, headers, body = @app.call env.dup if status == 200 and headers['Content-Type'] =~ /text\/html/ body = @processor.new(self, env).process body end return status, headers, body end |
- (Object) queue(&block)
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack-esi.rb', line 20 def queue(&block) unless @queue @queue, @group = Queue.new, ThreadGroup.new @poolsize.times { @group.add Worker.new(@queue) } at_exit { Finisher.wait @queue } end @queue.push block end |