-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from stereobooster/master
Windows support!
- Loading branch information
Showing
7 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
module Guard | |||
class Windows < Listener | |||
attr_reader :fchange | |||
|
|||
def initialize | |||
super | |||
@fchange = FChange::Notifier.new | |||
end | |||
|
|||
def on_change(&callback) | |||
@fchange.watch(Dir.pwd, :all_events, :recursive) do |event| | |||
paths = [File.expand_path(event.watcher.path) + '/'] | |||
files = modified_files(paths, {:all => true}) | |||
update_last_event | |||
callback.call(files) | |||
end | |||
end | |||
|
|||
def start | |||
@fchange.run | |||
end | |||
|
|||
def stop | |||
@fchange.stop | |||
end | |||
|
|||
def self.usable? | |||
require 'rb-fchange' | |||
true | |||
rescue LoadError | |||
UI.info "Please install rb-fchange gem for Windows file events support" | |||
false | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,88 @@ | |||
require 'spec_helper' | |||
require 'guard/listeners/windows' | |||
|
|||
describe Guard::Windows do | |||
subject { Guard::Windows } | |||
|
|||
if linux? | |||
it "isn't usable on linux" do | |||
subject.should_not be_usable | |||
end | |||
end | |||
|
|||
if mac? | |||
it "isn't usable on Mac" do | |||
subject.should_not be_usable | |||
end | |||
end | |||
|
|||
if windows? | |||
it "is usable on Windows 2000 and later" do | |||
subject.should be_usable | |||
end | |||
|
|||
describe "#on_change" do | |||
before(:each) do | |||
@results = [] | |||
@listener = Guard::Windows.new | |||
@listener.on_change do |files| | |||
@results += files | |||
end | |||
end | |||
|
|||
it "catches new file" do | |||
file = @fixture_path.join("newfile.rb") | |||
if File.exists?(file) | |||
begin | |||
File.delete file | |||
rescue | |||
end | |||
end | |||
File.exists?(file).should be_false | |||
start | |||
FileUtils.touch file | |||
stop | |||
begin | |||
File.delete file | |||
rescue | |||
end | |||
@results.should == ['spec/fixtures/newfile.rb'] | |||
end | |||
|
|||
it "catches file update" do | |||
file = @fixture_path.join("folder1/file1.txt") | |||
File.exists?(file).should be_true | |||
start | |||
FileUtils.touch file | |||
stop | |||
@results.should == ['spec/fixtures/folder1/file1.txt'] | |||
end | |||
|
|||
it "catches files update" do | |||
file1 = @fixture_path.join("folder1/file1.txt") | |||
file2 = @fixture_path.join("folder1/folder2/file2.txt") | |||
File.exists?(file1).should be_true | |||
File.exists?(file2).should be_true | |||
start | |||
FileUtils.touch file1 | |||
FileUtils.touch file2 | |||
stop | |||
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt'] | |||
end | |||
end | |||
end | |||
|
|||
private | |||
|
|||
def start | |||
sleep 0.6 | |||
Thread.new { @listener.start } | |||
sleep 0.6 | |||
end | |||
|
|||
def stop | |||
sleep 0.6 | |||
@listener.stop | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters