Class: Rack::ESI

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (ESI) initialize(app, options = {})

Returns a new instance of ESI



10
11
12
13
14
15
16
17
18
# File 'lib/rack-esi.rb', line 10

def initialize(app, options = {})
  @app        = app

  @parser     = options.fetch :parser, Nokogiri::XML::Document
  @serializer = options.fetch :serializer, :to_xhtml
  @skip       = options[:skip]
  @poolsize   = options.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