Class: Adva::Static::Server::Watch::Handler

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/adva/static/server/watch/handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(observable, pattern) ⇒ Handler

Returns a new instance of Handler.



10
11
12
13
14
15
# File 'lib/adva/static/server/watch/handler.rb', line 10

def initialize(observable, pattern)
  add_observer(observable)
  @pattern = pattern
  @current = Dir[pattern]
  @mtime   = Time.now
end

Instance Method Details

#listenObject



17
18
19
# File 'lib/adva/static/server/watch/handler.rb', line 17

def listen
  loop { trigger; sleep(0.5) }
end

#triggerObject



21
22
23
24
25
26
# File 'lib/adva/static/server/watch/handler.rb', line 21

def trigger
  events.each do |path, event|
    changed(true)
    notify_observers(path.dup, event)
  end
end