Class: Guard::LiveReload

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/livereload.rb,
lib/guard/livereload/reactor.rb,
lib/guard/livereload/snippet.rb,
lib/guard/livereload/websocket.rb

Defined Under Namespace

Classes: Reactor, Snippet, WebSocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LiveReload

Returns a new instance of LiveReload.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/guard/livereload.rb', line 11

def initialize(options = {})
  super

  js_path = File.expand_path('../../../js/livereload.js.erb', __FILE__)
  @options = {
    host:           '0.0.0.0',
    port:           '35729',
    apply_css_live: true,
    override_url:   false,
    grace_period:   0,
    js_template: js_path
  }.merge(options)

  js_path = @options[:js_template]

  # NOTE: save snippet as instvar, so it's not GC'ed
  @snippet = Snippet.new(js_path, @options)
  @options[:livereload_js_path] = @snippet.path
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#reactorObject

Returns the value of attribute reactor.



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

def reactor
  @reactor
end

Instance Method Details

#run_on_modifications(paths) ⇒ Object



39
40
41
42
# File 'lib/guard/livereload.rb', line 39

def run_on_modifications(paths)
  sleep options[:grace_period]
  reactor.reload_browser(paths)
end

#startObject



31
32
33
# File 'lib/guard/livereload.rb', line 31

def start
  @reactor = Reactor.new(options)
end

#stopObject



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

def stop
  reactor.stop
end