Permalink
Browse files

Optional user defined return with guard options[:any_return]

  • Loading branch information...
1 parent bdfdf45 commit 037b1e6febfa11a885690fcb51dec32fed03dc77 @earlonrails committed Oct 10, 2011
Showing with 6 additions and 7 deletions.
  1. +3 −4 lib/guard/guard.rb
  2. +2 −2 lib/guard/watcher.rb
  3. +1 −1 spec/guard/watcher_spec.rb
View
@@ -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
@@ -46,7 +46,7 @@ def self.match_files(guard, files)
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 @@ def self.match_files(guard, files)
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
@@ -49,7 +49,7 @@
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

0 comments on commit 037b1e6

Please sign in to comment.