Class: Rack::LiveReload

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/livereload.rb,
lib/rack/livereload/body_processor.rb,
lib/rack/livereload/processing_skip_analyzer.rb,
lib/rack-livereload.rb

Defined Under Namespace

Classes: BodyProcessor, ProcessingSkipAnalyzer

Constant Summary collapse

VERSION =
'0.3.16'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LiveReload.



9
10
11
# File 'lib/rack/livereload.rb', line 9

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/rack/livereload.rb', line 7

def app
  @app
end

Instance Method Details

#_call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rack/livereload.rb', line 17

def _call(env)
  _, path, file = (env['PATH_INFO'] || '').split('/')

  if path == '__rack' && ::File.file?(target = ::File.expand_path("../../../js/#{file}", __FILE__))
    deliver_file(target)
  else
    status, headers, body = result = @app.call(env)

    return result if ProcessingSkipAnalyzer.skip_processing?(result, env, @options)

    processor = BodyProcessor.new(body, @options)
    processor.process!(env)

    headers['Content-Length'] = processor.content_length.to_s

    if processor.livereload_added
      headers['X-Rack-LiveReload'] = '1'
    end

    [ status, headers, processor.new_body ]
  end
end

#call(env) ⇒ Object



13
14
15
# File 'lib/rack/livereload.rb', line 13

def call(env)
  dup._call(env)
end