watcher cleaned up.
This commit is contained in:
parent
a7b6ebeef1
commit
b2f282f1e8
@ -6,15 +6,16 @@ module Guard
|
||||
#
|
||||
class Watcher
|
||||
|
||||
attr_accessor :pattern, :action, :any_rtn
|
||||
attr_accessor :pattern, :action, :any_return
|
||||
|
||||
# Initialize a file watcher.
|
||||
#
|
||||
# @param [String, Regexp] pattern the pattern to be watched by the guard
|
||||
# @param [Block] action the action to execute before passing the result to the Guard
|
||||
# @param [Boolean] any_return allow the user to define return when using a block
|
||||
#
|
||||
def initialize(pattern, action = nil, any_rtn = false)
|
||||
@pattern, @action, @any_rtn = pattern, action, any_rtn
|
||||
def initialize(pattern, action = nil, any_return = false)
|
||||
@pattern, @action, @any_return = pattern, action, any_return
|
||||
@@warning_printed ||= false
|
||||
|
||||
# deprecation warning
|
||||
@ -41,12 +42,11 @@ module Guard
|
||||
# @return [Array<Object>] the matched watcher response
|
||||
def self.match_files(guard, files)
|
||||
guard.watchers.inject([]) do |paths, watcher|
|
||||
wa = watcher.any_rtn
|
||||
files.each do |file|
|
||||
if matches = watcher.match_file?(file)
|
||||
if watcher.action
|
||||
result = watcher.call_action(matches)
|
||||
if wa
|
||||
if watcher.any_return
|
||||
paths << result
|
||||
elsif result.respond_to?(:empty?) && ! result.empty?
|
||||
paths << Array(result)
|
||||
@ -57,7 +57,7 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
wa ? paths : paths.flatten.map{|p| p.to_s}
|
||||
watcher.any_return ? paths : paths.flatten.map{|p| p.to_s}
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user