Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inotify support for linux #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fsevents_to_vm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "rb-fsevent", "~> 0.9.5"
spec.add_dependency "rb-inotify", "~> 0.9.5"
spec.add_dependency "thor", "~> 0.19.1"
spec.add_dependency "net-ssh", "~> 2.9.2"

Expand Down
1 change: 1 addition & 0 deletions lib/fsevents_to_vm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "fsevents_to_vm/version"

require 'fsevents_to_vm/event'
require 'fsevents_to_vm/fs_event_proxy'
require 'fsevents_to_vm/watch'
require 'fsevents_to_vm/path_filter'
require 'fsevents_to_vm/recursion_filter'
Expand Down
52 changes: 52 additions & 0 deletions lib/fsevents_to_vm/fs_event_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
def is_mac?
RUBY_PLATFORM.downcase.include?("darwin")
end

def is_linux?
RUBY_PLATFORM.downcase.include?("linux")
end

require 'rb-inotify' if is_linux?
require 'rb-fsevent' if is_mac?

module FseventsToVm
class FsEventProxy

attr_reader :notifier

#
# Accepts the ablosute_path which the notifier
# will monitor
#
def initialize(absolute_path)
@path = absolute_path
@notifier = INotify::Notifier.new if is_linux?
@notifier = FSEvent.new if is_mac?
end

#
# Accepts a Proc object containing the code
# to be executed when a notifier event occurs
#
def watch(&block)
if is_mac?
@notifier.watch([@path], file_events: true) do |event|
block.call(event)
end
elsif is_linux?
@notifier.watch(@path, :recursive, :attrib, :modify, :move, :create, :delete) do |event|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't test it.

block.call([event.absolute_name])
end
end
puts "Watching #{@path}"
end

def run
@notifier.run
end

def stop
@notifier.stop
end
end
end
10 changes: 4 additions & 6 deletions lib/fsevents_to_vm/watch.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'rb-fsevent'

module FseventsToVm
class Watch
def initialize(*listen_dirs)
@listen_dirs = listen_dirs
@fs = FSEvent.new
def initialize(listen_dir)
@listen_dir = listen_dir
@fs = FsEventProxy.new(@listen_dir)
end

def run
@fs.watch(@listen_dirs, file_events: true) do |files|
@fs.watch do |files|
files.each do |file|
event = build_event(file)
yield event if event
Expand Down