Class: Guard::LiveReload::Reactor

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/livereload/reactor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Reactor

Returns a new instance of Reactor.



8
9
10
11
12
13
# File 'lib/guard/livereload/reactor.rb', line 8

def initialize(options)
  @web_sockets       = []
  @options           = options
  @thread            = Thread.new { _start_reactor }
  @connections_count = 0
end

Instance Attribute Details

#connections_countObject (readonly)

Returns the value of attribute connections_count.



6
7
8
# File 'lib/guard/livereload/reactor.rb', line 6

def connections_count
  @connections_count
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/guard/livereload/reactor.rb', line 6

def options
  @options
end

#threadObject (readonly)

Returns the value of attribute thread.



6
7
8
# File 'lib/guard/livereload/reactor.rb', line 6

def thread
  @thread
end

#web_socketsObject (readonly)

Returns the value of attribute web_sockets.



6
7
8
# File 'lib/guard/livereload/reactor.rb', line 6

def web_sockets
  @web_sockets
end

Instance Method Details

#reload_browser(paths = []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/guard/livereload/reactor.rb', line 19

def reload_browser(paths = [])
  msg = "Reloading browser: #{paths.join(' ')}"
  Compat::UI.info msg
  if options[:notify]
    Compat::UI.notify(msg, title: 'Reloading browser', image: :success)
  end

  paths.each do |path|
    data = _data(path)
    Compat::UI.debug(data)
    web_sockets.each { |ws| ws.send(MultiJson.encode(data)) }
  end
end

#stopObject



15
16
17
# File 'lib/guard/livereload/reactor.rb', line 15

def stop
  thread.kill
end