Class: Rack::Chartbeat

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/chartbeat.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Chartbeat

Returns a new instance of Chartbeat.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/rack/chartbeat.rb', line 6

def initialize(app, options = {})
  raise ArgumentError, "Chartbeat UID Required" unless options[:uid]
  raise ArgumentError, "Domain Required" unless options[:domain] &&
    !options[:domain].empty?
  @app, @options = app, options
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/chartbeat.rb', line 13

def call(env)
  @status, @headers, @response = @app.call(env)
  return [@status, @headers, @response] unless html?
  response = Rack::Response.new([], @status, @headers)
  if @response.respond_to?(:to_ary)
    @response.each do |fragment| 
      response.write inject_chartbeat(fragment)
    end
  end
  response.finish
end