guard-copy 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -57,16 +57,17 @@ the directory specified by the `:from` option to that specified by the
57
57
  ### List of available options:
58
58
 
59
59
  ``` ruby
60
- :from => 'source' # directory to copy files from
61
- :to => 'target' # directory or glob to copy files to; string or array
62
- :glob => :newest # how to handle globs; default: :all
63
- # :newest - copy to only the newest directory
64
- # :all - copy to all directories
65
- :mkpath => true # create directories in target when full target path
66
- # does not exist; default: false
67
- :delete => true # delete files from target directories; default: false
68
- :verbose => true # log all operations as info messages; default: false
69
- :absolute => true # allow absolute paths for :to; default: false
60
+ :from => 'source' # directory to copy files from
61
+ :to => 'target' # directory or glob to copy files to; string or array
62
+ :glob => :newest # how to handle globs; default: :all
63
+ # :newest - copy to only the newest directory
64
+ # :all - copy to all directories
65
+ :mkpath => true # create directories in target when full target path
66
+ # does not exist; default: false
67
+ :delete => true # delete files from target directories; default: false
68
+ :verbose => true # log all operations as info messages; default: false
69
+ :absolute => true # allow absolute paths for :to; default: false
70
+ :run_at_start => true # copy all files at startup (does not remove any files)
70
71
  ```
71
72
 
72
73
  ## Watchers
@@ -30,15 +30,18 @@ module Guard
30
30
  validate_presence_of(:to)
31
31
  validate_to_patterns_are_not_absolute
32
32
  validate_to_does_not_include_from
33
- resolve_targets
33
+ resolve_targets!
34
34
  validate_no_targets_are_files
35
35
  display_target_paths
36
+
37
+ run_all if options[:run_at_start]
36
38
  end
37
39
 
38
40
  # Called when just `enter` is pressed
39
41
  # This method should be principally used for long action like running all specs/tests/...
40
42
  # @raise [:task_has_failed] when run_all has failed
41
43
  def run_all
44
+ run_on_changes(Watcher.match_files(self, Dir.glob("**/*.*")))
42
45
  end
43
46
 
44
47
  # Called on file(s) modifications that the Guard watches.
@@ -148,12 +151,8 @@ module Guard
148
151
  end
149
152
  end
150
153
 
151
- def resolve_targets
152
- @targets.each do |target|
153
- unless target.resolve
154
- UI.warning("Guard::Copy - '#{target.pattern}' does not match a valid directory")
155
- end
156
- end
154
+ def resolve_targets!
155
+ @targets.each { |target| target.resolve! }
157
156
  end
158
157
 
159
158
  def validate_no_targets_are_files
@@ -2,7 +2,7 @@ module Guard
2
2
  class Copy
3
3
  class Target
4
4
 
5
- attr_reader :pattern, :options, :paths
5
+ attr_reader :pattern, :paths, :glob
6
6
 
7
7
  # Initialize a new target
8
8
  #
@@ -13,28 +13,44 @@ module Guard
13
13
  raise ArgumentError, 'pattern cannot be nil' unless pattern
14
14
  raise ArgumentError, 'pattern cannot be empty' if pattern.empty?
15
15
  @pattern = pattern
16
- @options = {
17
- :glob => :all
18
- }.merge(options)
16
+ @glob = options[:glob] || :all
17
+ @expand_pattern = !options[:mkpath]
19
18
  @paths = []
20
19
  end
21
20
 
22
21
  # Resolve the target into one or more paths
23
- #
24
- # @return [Boolean] true if the pattern resolved to any paths
25
- def resolve
26
- @paths.clear
27
- if @options[:glob] == :newest
28
- @paths.concat(Dir[@pattern].sort_by { |f| File.mtime(f) }.last(1))
22
+ def resolve!
23
+ paths.clear
24
+ if expand_pattern?
25
+ expand_pattern
29
26
  else
30
- @paths.concat(Dir[@pattern])
27
+ paths << pattern
31
28
  end
32
- @paths.any?
29
+ warn_if_empty
33
30
  end
34
31
 
35
32
  # @return [Boolean] true if the pattern is an absolute path
36
33
  def absolute?
37
- @pattern.start_with?('/')
34
+ pattern.start_with?('/')
35
+ end
36
+
37
+ private
38
+
39
+ def expand_pattern?; @expand_pattern; end
40
+
41
+ def expand_pattern
42
+ case glob
43
+ when :newest
44
+ paths.concat(Dir[pattern].sort_by { |f| File.mtime(f) }.last(1))
45
+ when :all
46
+ paths.concat(Dir[pattern])
47
+ end
48
+ end
49
+
50
+ def warn_if_empty
51
+ unless paths.any?
52
+ UI.warning("Guard::Copy - '#{pattern}' does not match a valid directory")
53
+ end
38
54
  end
39
55
 
40
56
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module CopyVersion
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-12 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -54,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  segments:
56
56
  - 0
57
- hash: -3415023527263966142
57
+ hash: 3047131128220204407
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  none: false
60
60
  requirements:
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  segments:
65
65
  - 0
66
- hash: -3415023527263966142
66
+ hash: 3047131128220204407
67
67
  requirements: []
68
68
  rubyforge_project:
69
69
  rubygems_version: 1.8.24