guard-copy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Marc Schwieterman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Guard::Copy [![Build Status](https://secure.travis-ci.org/marcisme/guard-copy.png?branch=master)](http://travis-ci.org/marcisme/guard-copy)
2
+
3
+ Copy guard copies files to one or more locations whenever files are
4
+ created or modified.
5
+
6
+ * Tested against Ruby 1.8.7, 1.9.2, 1.9.3, and the latest versions of JRuby
7
+
8
+ ## Installation
9
+
10
+ Please be sure to have [Guard](https://github.com/guard/guard)
11
+ installed.
12
+
13
+ Install the gem:
14
+
15
+ $ gem install guard-copy
16
+
17
+ Add guard definition to your Guardfile by running this command:
18
+
19
+ $ guard init copy
20
+
21
+ ## Usage
22
+
23
+ Please read [Guard usage doc](https://github.com/guard/guard#readme)
24
+
25
+ ## Guardfile
26
+
27
+ Copy guard can copy files from one source directory to one or more
28
+ target directories identified either explicitly or with wildcards.
29
+
30
+ ### Single Target
31
+
32
+ ``` ruby
33
+ guard :copy, :from => 'source', :to => 'target'
34
+ ```
35
+
36
+ ### Multiple Targets
37
+
38
+ ``` ruby
39
+ guard :copy, :from => 'source', :to => ['t1', 't2']
40
+ ```
41
+
42
+ ### Newest Wildcard Target
43
+
44
+ ``` ruby
45
+ guard :copy, :from => 'source', :to => 'target*', :glob => :newest
46
+ ```
47
+
48
+ This guard will copy files from the source directory to the newest
49
+ directory starting with 'target'.
50
+
51
+ ## Author
52
+
53
+ [Marc Schwieterman](https://github.com/marcisme)
54
+
55
+ ## License
56
+
57
+ Copyright (c) 2012 Marc Schwieterman
58
+
59
+ MIT License
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of this software and associated documentation files (the
63
+ "Software"), to deal in the Software without restriction, including
64
+ without limitation the rights to use, copy, modify, merge, publish,
65
+ distribute, sublicense, and/or sell copies of the Software, and to
66
+ permit persons to whom the Software is furnished to do so, subject to
67
+ the following conditions:
68
+
69
+ The above copyright notice and this permission notice shall be
70
+ included in all copies or substantial portions of the Software.
71
+
72
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
73
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
75
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
76
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
77
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
78
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/guard/copy.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/copy/version'
4
+
5
+ module Guard
6
+ class Copy < Guard
7
+
8
+ # Initialize a Guard.
9
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
10
+ # @param [Hash] options the custom Guard options
11
+ def initialize(watchers = [], options = {})
12
+ # watchers are currently ignored
13
+ watchers << ::Guard::Watcher.new(%r{#{options[:from]}/.*})
14
+ @targets = options[:to].is_a?(Array) ? options[:to] : [options[:to]]
15
+ UI.info("Guard::Copy will copy files from '#{options[:from]}' to '#{@targets.first}'")
16
+ super
17
+ end
18
+
19
+ # Call once when Guard starts. Please override initialize method to init stuff.
20
+ # @raise [:task_has_failed] when start has failed
21
+ def start
22
+ end
23
+
24
+ # Called when just `enter` is pressed
25
+ # This method should be principally used for long action like running all specs/tests/...
26
+ # @raise [:task_has_failed] when run_all has failed
27
+ def run_all
28
+ end
29
+
30
+ # Called on file(s) modifications that the Guard watches.
31
+ # @param [Array<String>] paths the changes files or paths
32
+ # @raise [:task_has_failed] when run_on_change has failed
33
+ def run_on_change(paths)
34
+ paths.each do |from_path|
35
+ @targets.each do |target|
36
+ target_dirs = target_dirs(target)
37
+ if target_dirs.empty?
38
+ UI.error("'#{target}' does not match any directories")
39
+ else
40
+ copy(from_path, target_dirs)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ # Called on file(s) deletions that the Guard watches.
47
+ # @param [Array<String>] paths the deleted files or paths
48
+ # @raise [:task_has_failed] when run_on_change has failed
49
+ def run_on_deletion(paths)
50
+ end
51
+
52
+ private
53
+
54
+ def target_dirs(target)
55
+ if @options[:glob] == :newest
56
+ Dir[target].sort_by { |f| File.mtime(f) }.last(1)
57
+ else
58
+ Dir[target]
59
+ end
60
+ end
61
+
62
+ def copy(from_path, target_dirs)
63
+ target_dirs.each do |target_dir|
64
+ if File.directory?(target_dir)
65
+ to_path = from_path.sub(@options[:from], target_dir)
66
+ FileUtils.cp(from_path, to_path)
67
+ else
68
+ UI.error("'#{target_dir}' is not a directory")
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ # Any files created or modified in the 'source' directory
2
+ # will be copied to the 'target' directory. Update the
3
+ # guard as appropriate for your needs.
4
+
5
+ guard :copy, :from => 'source', :to => 'target'
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module CopyVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-copy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marc Schwieterman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: aruba
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.4'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0.8'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0.8'
94
+ description: Guard::Copy automatically copies files.
95
+ email:
96
+ - marc.schwieterman@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - lib/guard/copy/templates/Guardfile
102
+ - lib/guard/copy/version.rb
103
+ - lib/guard/copy.rb
104
+ - LICENSE
105
+ - README.md
106
+ homepage: https://github.com/marcisme/guard-copy
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 1.8.24
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Guard gem for copy
130
+ test_files: []