fssm
fssm copied to clipboard
improve documentation around using FSSM inside an OO class
I'm stumped on how to make it work in a pretty basic class:
class Watcher
def start
monitor = FSSM::Monitor.new(:directories => true)
monitor.path('test_data/', '**/*') do
update do |base, relative, ftype|
output(relative)
end
create do |base, relative, ftype|
output(relative)
end
# don't really care about delete right now
delete { |base, relative, ftype| puts "DELETED #{relative} (#{ftype})" }
end
monitor.run
end
def output(relative)
puts "WOOT! #{relative}"
end
end
In this relatively contrived case, it seems that in the update and create callbacks, it has no visibility to the instance-level output() method. I'm flummoxed on how to solve this. If I instantiate a new Watcher and do watcher.start it runs fine, but as soon as a file change occurs, all I get is:
undefined local variable or method `output' for /Users/mpatterson/mywatcher/test_data:FSSM::Path (FSSM::CallbackError)
(reposted here from an email exchange between ttilley and myself so that he can update the docs with the explanation he gave me)
+1
+1 Found it try the following code. i"s all about |path| variable that is passed to the block. It allow switching to the correct context
Hope this help !! Cheers
class Watcher
def start
monitor = FSSM::Monitor.new(:directories => true)
monitor.path('test_data/', '**/*') do |path|
path.update do |base, relative, ftype|
output(relative)
end
path.create do |base, relative, ftype|
output(relative)
end
# don't really care about delete right now
path.delete { |base, relative, ftype| puts "DELETED #{relative} (#{ftype})" }
end
monitor.run
end
def output(relative)
puts "WOOT! #{relative}"
end
end