Optional user defined return with guard options[:any_return]

This commit is contained in:
Kevin Krauss 2011-10-10 13:38:14 -07:00
parent bdfdf45325
commit 037b1e6feb
3 changed files with 6 additions and 7 deletions

View File

@ -30,17 +30,16 @@ module Guard
class Guard
include Hook
attr_accessor :watchers, :options, :group, :any_return
attr_accessor :watchers, :options, :group
# Initialize a Guard.
#
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
# @param [Hash] options the custom Guard options
# @param [Boolean] any_return allow the user to define return when using a block with a watcher
#
def initialize(watchers = [], options = {}, any_return = false)
def initialize(watchers = [], options = {})
@group = options[:group] ? options.delete(:group).to_sym : :default
@watchers, @options, @any_return = watchers, options, any_return
@watchers, @options = watchers, options
end
# Initialize the Guard. This will copy the Guardfile template inside the Guard gem.

View File

@ -46,7 +46,7 @@ module Guard
if matches = watcher.match_file?(file)
if watcher.action
result = watcher.call_action(matches)
if guard.any_return
if guard.options[:any_return]
paths << result
elsif result.respond_to?(:empty?) && !result.empty?
paths << Array(result)
@ -57,7 +57,7 @@ module Guard
end
end
guard.any_return ? paths : paths.flatten.map{ |p| p.to_s }
guard.options[:any_return] ? paths : paths.flatten.map{ |p| p.to_s }
end
end

View File

@ -49,7 +49,7 @@ describe Guard::Watcher do
before(:all) do
@guard = Guard::Guard.new
@guard_any_return = Guard::Guard.new
@guard_any_return.any_return = true
@guard_any_return.options[:any_return] = true
end
context "with a watcher without action" do