Class: Rack::LiveReload::ProcessingSkipAnalyzer

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

Constant Summary collapse

BAD_USER_AGENTS =
[ %r{MSIE} ]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result, env, options) ⇒ ProcessingSkipAnalyzer

Returns a new instance of ProcessingSkipAnalyzer.


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

def initialize(result, env, options)
  @env, @options = env, options

  @status, @headers, @body = result
end

Class Method Details

.skip_processing?(result, env, options) ⇒ Boolean

Returns:

  • (Boolean)

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

def self.skip_processing?(result, env, options)
  new(result, env, options).skip_processing?
end

Instance Method Details

#bad_browser?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 35

def bad_browser?
  BAD_USER_AGENTS.any? { |pattern| @env['HTTP_USER_AGENT'] =~ pattern }
end

#chunked?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 22

def chunked?
  @headers['Transfer-Encoding'] == 'chunked'
end

#get?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 43

def get?
  @env['REQUEST_METHOD'] == 'GET'
end

#html?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 39

def html?
  @headers['Content-Type'] =~ %r{text/html}
end

#ignored?Boolean

Returns:

  • (Boolean)

30
31
32
33
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 30

def ignored?
  path = @env['QUERY_STRING'].empty? ? @env['PATH_INFO'] : "#{@env['PATH_INFO']}?#{@env['QUERY_STRING']}"
  @options[:ignore] and @options[:ignore].any? { |filter| path[filter] }
end

#inline?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 26

def inline?
  @headers['Content-Disposition'] =~ %r{^inline}
end

#skip_processing?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/rack/livereload/processing_skip_analyzer.rb', line 18

def skip_processing?
  !html? || chunked? || inline? || ignored? || bad_browser? || !get?
end