Skip to content

Commit

Permalink
add watched_directories
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Dec 11, 2014
1 parent 9b2c33b commit f6d3e74
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/guard/compat/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def run_all
def run_on_modifications
Guard::Compat::UI.color_enabled?
Guard::Compat.matching_files(self, ['foo'])
Guard::Compat.watched_directories
end
end
end
16 changes: 16 additions & 0 deletions lib/guard/compat/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def self.matching_files(plugin, files)
Guard::Watcher.match_files(plugin, files).uniq
end

def self.watched_directories
unless Guard.const_defined?('CLI')
msg = 'either Guard has not been required or you did not' \
' stub this method in your plugin tests'
fail NotImplementedError, msg
end

if Guard.respond_to?(:state)
# TODO: the new version is temporary
Guard.state.session.watchdirs.map { |d| Pathname(d) }
else
dirs = Array(Guard.options(:watchdir))
dirs.empty? ? [Pathname.pwd] : dirs.map { |d| Pathname(d) }
end
end

module UI
def self.color(text, *colors)
Guard::UI.send(:color, text, *colors)
Expand Down
1 change: 1 addition & 0 deletions spec/guard/compat/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
describe '#run_on_modifications' do
before do
allow(Guard::Compat).to receive(:matching_files)
allow(Guard::Compat).to receive(:watched_directories)
end

before { subject.run_on_modifications }
Expand Down

0 comments on commit f6d3e74

Please sign in to comment.