diff --git a/Guardfile b/Guardfile index 7cd30ab..826ffb6 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard :rspec, :version => 2, :keep_failed => false, :cli => '-f doc' do +guard 'rspec', :version => 2, :keep_failed => false, :cli => '-f doc' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/lib/core_ext/hash_with_indifferent_access.rb b/lib/core_ext/hash_with_indifferent_access.rb new file mode 100644 index 0000000..cfb83e7 --- /dev/null +++ b/lib/core_ext/hash_with_indifferent_access.rb @@ -0,0 +1,9 @@ +class Thor + module CoreExt #:nodoc: + class HashWithIndifferentAccess < ::Hash #:nodoc: + def has_key?(key) + super(convert_key(key)) + end + end + end +end diff --git a/lib/guard.rb b/lib/guard.rb index a297f12..a9559d9 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -1,3 +1,6 @@ +require 'core_ext/hash_with_indifferent_access' +#require 'pry' + module Guard autoload :UI, 'guard/ui' @@ -14,7 +17,7 @@ module Guard # initialize this singleton def setup(options = {}) @options = options - @listener = Listener.select_and_init + @listener = Listener.select_and_init((options[:watchdir]) ? File.expand_path(options[:watchdir]) : Dir.pwd) @guards = [] @options[:notify] && ENV["GUARD_NOTIFY"] != 'false' ? Notifier.turn_on : Notifier.turn_off @@ -35,7 +38,7 @@ module Guard run { run_on_change_for_all_guards(files) } if Watcher.match_files?(guards, files) end - UI.info "Guard is now watching at '#{Dir.pwd}'" + UI.info "Guard is now watching at '#{listener.directory}'" guards.each { |guard| supervised_task(guard, :start) } listener.start end @@ -50,7 +53,7 @@ module Guard end # Reparse the whole directory to catch new files modified during the guards run - new_modified_files = listener.modified_files([Dir.pwd], :all => true) + new_modified_files = listener.modified_files([listener.directory], :all => true) if !new_modified_files.empty? && Watcher.match_files?(guards, new_modified_files) run { run_on_change_for_all_guards(new_modified_files) } end diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index 9bf323a..2193558 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -10,6 +10,9 @@ module Guard method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages" method_option :group, :type => :array, :default => [], :aliases => '-g', :banner => "Run only the passed groups" + method_option :guardfile, :type => :string, :aliases => '-C', :banner => "Specify a Guardfile" + method_option :watchdir, :type => :string, :default => '.', :aliases => '-w', :banner => "Specify the directory to watch" + desc "start", "Starts Guard" def start ::Guard.start(options) diff --git a/lib/guard/listener.rb b/lib/guard/listener.rb index ae8b07a..1a8eeaf 100644 --- a/lib/guard/listener.rb +++ b/lib/guard/listener.rb @@ -9,6 +9,8 @@ module Guard autoload :Polling, 'guard/listeners/polling' class Listener + + attr_reader :directory def self.select_and_init(*a) if mac? && Darwin.usable?