Class: FSSM::Backends::RBFSEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/fssm/backends/rbfsevent.rb

Instance Method Summary collapse

Constructor Details

#initializeRBFSEvent

Returns a new instance of RBFSEvent.


3
4
5
# File 'lib/fssm/backends/rbfsevent.rb', line 3

def initialize
  @handlers = []
end

Instance Method Details

#add_handler(handler, preload = true) ⇒ Object


7
8
9
10
# File 'lib/fssm/backends/rbfsevent.rb', line 7

def add_handler(handler, preload=true)
  @handlers << handler
  handler.refresh(nil, true) if preload
end

#runObject


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fssm/backends/rbfsevent.rb', line 12

def run
  begin
    @fsevent = FSEvent.new
    @fsevent.watch(temporary_multipath_hack) do |paths|
      paths.each do |path|
        temporary_multipath_handler(path)
      end
    end
    @fsevent.run
  rescue Interrupt
    @fsevent.stop
  end
end

#temporary_multipath_hackObject


36
37
38
39
# File 'lib/fssm/backends/rbfsevent.rb', line 36

def temporary_multipath_hack
  @handlers = @handlers.sort {|x,y| y.path.to_pathname.segments.length <=> x.path.to_pathname.segments.length}
  return @handlers.map {|handler| handler.path.to_s}
end

#temporary_multipath_handler(path) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/fssm/backends/rbfsevent.rb', line 26

def temporary_multipath_handler(path)
  @handlers.each do |handler|
    handler_path = File.join(handler.path.to_s, "")
    if path.start_with?(handler_path)
      handler.refresh(path)
      break
    end
  end
end