Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert root directory support via '.'

This was a bad idea, as explained in #15. It should have been implemented
as YAFO. (and in a feature branch)

This reverts commits:

67be71b
b02df2c
  • Loading branch information...
commit 3590a5cc3d99b83bf77c7383acd18dcf2483ead2 1 parent b02df2c
@marcisme authored
View
2  README.md
@@ -57,7 +57,7 @@ the directory specified by the `:from` option to that specified by the
### List of available options:
``` ruby
-:from => 'source' # directory to copy files from; use '.' for root directory
+:from => 'source' # directory to copy files from
:to => 'target' # directory or glob to copy files to; string or array
:glob => :newest # how to handle globs; default: :all
# :newest - copy to only the newest directory
View
9 features/copy.feature
@@ -80,12 +80,3 @@ Feature: Copy files
When I create a file named "source/nes/ted/dir/ectory/foo"
Then "source/nes/ted/dir/ectory/foo" should be copied to "target/nes/ted/dir/ectory/foo"
- Scenario: Copy a file from the root directory
- Given a directory named "target"
- And I have run guard with this Guardfile:
- """
- guard :copy, :from => '.', :to => 'target'
- """
- When I create a file named "foo"
- Then "foo" should be copied to "target/foo"
-
View
81 lib/guard/copy.rb
@@ -5,51 +5,6 @@
module Guard
class Copy < Guard
- # TODO: starting to move some of the option related behavior into separate classes.
- # we probably need to separate validation that pertains to a valid configuration
- # and validation that is about the file system state at runtime
- # TODO: think more about how to manage inter-option dependencies
- class FromOption
-
- COPY_FROM_PROJECT_ROOT_MAGIC_STRING = '.'
-
- attr_reader :path
-
- def initialize(path)
- @path = path
- end
-
- def validate_is_directory!
- unless File.directory?(path)
- if File.file?(path)
- UI.error("Guard::Copy - '#{path}' is a file and must be a directory")
- throw :task_has_failed
- else
- UI.error("Guard::Copy - :from option does not contain a valid directory")
- throw :task_has_failed
- end
- end
- end
-
- def substitute_target_path(from_path, target_path)
- if path == COPY_FROM_PROJECT_ROOT_MAGIC_STRING
- target_path
- else
- from_path.sub(path, target_path)
- end
- end
-
- def default_watcher
- # sniff sniff
- if path == COPY_FROM_PROJECT_ROOT_MAGIC_STRING
- ::Guard::Watcher.new(%r{^.*$})
- else
- ::Guard::Watcher.new(%r{^#{path}/.*$})
- end
- end
-
- end
-
autoload :Target, 'guard/copy/target'
attr_reader :targets
@@ -59,11 +14,10 @@ def default_watcher
# @param [Hash] options the custom Guard options
def initialize(watchers = [], options = {})
super
- @from = FromOption.new(options[:from])
if watchers.empty?
- watchers << from.default_watcher
+ watchers << ::Guard::Watcher.new(%r{^#{options[:from]}/.*$})
else
- watchers.each { |w| normalize_watcher(w) }
+ watchers.each { |w| normalize_watcher(w, options[:from]) }
end
@targets = Array(options[:to]).map { |to| Target.new(to, options) }
end
@@ -71,10 +25,8 @@ def initialize(watchers = [], options = {})
# Call once when Guard starts. Please override initialize method to init stuff.
# @raise [:task_has_failed] when start has failed
def start
- # TODO: This :from validation should probably go in the FromOption class,
- # but then we have to do something with the :to validation...
validate_presence_of(:from)
- from.validate_is_directory!
+ validate_from_is_directory
validate_presence_of(:to)
validate_to_patterns_are_not_absolute
validate_to_does_not_start_with_from
@@ -124,8 +76,6 @@ def run_on_removals(paths)
private
- attr_reader :from
-
def target_paths
@targets.map { |t| t.paths }.flatten
end
@@ -133,15 +83,15 @@ def target_paths
def with_all_target_paths(paths)
paths.each do |from_path|
target_paths.each do |target_path|
- to_path = from.substitute_target_path(from_path, target_path)
+ to_path = from_path.sub(@options[:from], target_path)
yield(from_path, to_path)
end
end
end
- def normalize_watcher(watcher)
- unless watcher.pattern.source =~ %r{^\^#{from.path}/.*}
- normalized_source = watcher.pattern.source.sub(%r{^\^?(#{from.path})?/?}, "^#{from.path}/")
+ def normalize_watcher(watcher, from)
+ unless watcher.pattern.source =~ %r{^\^#{from}/.*}
+ normalized_source = watcher.pattern.source.sub(%r{^\^?(#{from})?/?}, "^#{from}/")
UI.info('Guard::Copy is changing watcher pattern:')
UI.info(" #{watcher.pattern.source}")
UI.info('to:')
@@ -157,8 +107,21 @@ def validate_presence_of(option)
end
end
+ def validate_from_is_directory
+ path = options[:from]
+ unless File.directory?(path)
+ if File.file?(path)
+ UI.error("Guard::Copy - '#{path}' is a file and must be a directory")
+ throw :task_has_failed
+ else
+ UI.error("Guard::Copy - :from option does not contain a valid directory")
+ throw :task_has_failed
+ end
+ end
+ end
+
def validate_to_does_not_start_with_from
- if Array(options[:to]).any? { |to| to.start_with?(from.path) }
+ if Array(options[:to]).any? { |to| to.start_with?(options[:from]) }
UI.error('Guard::Copy - :to must not start with :from')
throw :task_has_failed
end
@@ -215,7 +178,7 @@ def validate_to_patterns_are_not_absolute
def display_target_paths
if target_paths.any?
UI.info("Guard::Copy - files in:")
- UI.info(" #{from.path}")
+ UI.info(" #{options[:from]}")
UI.info("will be copied to#{ ' and removed from' if options[:delete] }:")
target_paths.each { |target_path| UI.info(" #{target_path}") }
end
View
13 spec/guard/copy_spec.rb
@@ -267,19 +267,6 @@ module Guard
File.should be_file('t2/foo')
end
- it 'copies files from the root directory to target directories' do
- file('foo')
- dir('t1')
- dir('t2')
- guard = Copy.new([], :from => '.', :to => ['t1', 't2'])
- guard.start
-
- guard.run_on_changes(['foo'])
-
- File.should be_file('t1/foo')
- File.should be_file('t2/foo')
- end
-
it 'warns when a directory containing a "." is changed' do
dir('source/dotted.name')
dir('target/dotted.name')
Please sign in to comment.
Something went wrong with that request. Please try again.