maid 0.2.3.alpha.1 → 0.3.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS.md CHANGED
@@ -1,9 +1,7 @@
1
1
  In alphabetical order:
2
2
 
3
3
  * Benjamin Oakes (@benjaminoakes)
4
- * Bradley Smith (@bradleyd)
5
4
  * Larry Lv (@larrylv)
6
5
  * Lewis O'Driscoll (@loddy1234)
7
6
  * Lloyd Philbrook (@phoolish)
8
7
  * Mark Jaquith (@markjaquith)
9
- * Mu Ye (@yemutex)
data/ChangeLog CHANGED
@@ -1,11 +1,10 @@
1
- maid (0.2.3.alpha.1) unstable; urgency=low
1
+ maid (0.3.0.beta.1) unstable; urgency=high
2
2
 
3
- * Mu Ye: Improve command line spec coverage (Closes: #97)
4
- * Changed from ArgumentError to NotImplementedError when a command is
5
- unsupported on the host OS.
6
- * Bradley Smith: Add locate support on Ubuntu (Closes: #67)
3
+ * Only allow "move" to move to existing directories. Renaming files
4
+ can be accomplished with the new "rename" tool. This fixes a bug in
5
+ overwrite warnings. (Closes: #87)
7
6
 
8
- -- Benjamin Oakes <hello@benjaminoakes.com> Fri, 8 Mar 2013 00:00:00 +0000
7
+ -- Benjamin Oakes <hello@benjaminoakes.com> Sun, 24 Feb 2013 00:00:00 +0000
9
8
 
10
9
  maid (0.2.2) stable; urgency=high
11
10
 
data/lib/maid/maid.rb CHANGED
@@ -98,7 +98,7 @@ class Maid::Maid
98
98
  if supported_command?(command)
99
99
  %x(#{ command })
100
100
  else
101
- raise NotImplementedError, "Unsupported system command: #{ command.inspect }"
101
+ raise ArgumentError, "Unsupported system command: #{ command.inspect }"
102
102
  end
103
103
  end
104
104
 
data/lib/maid/platform.rb CHANGED
@@ -13,16 +13,5 @@ module Maid::Platform
13
13
  def osx?
14
14
  !!(host_os =~ /darwin/i)
15
15
  end
16
-
17
- end
18
-
19
- # Commands based on OS type
20
- class Commands
21
- class << self
22
- # logicaly decides which locate command to use
23
- def locate
24
- Maid::Platform.linux? ? 'locate' : 'mdfind -name'
25
- end
26
- end
27
16
  end
28
17
  end
data/lib/maid/tools.rb CHANGED
@@ -15,9 +15,9 @@ module Maid::Tools
15
15
  # For showing deprecation notices
16
16
  include Deprecated
17
17
 
18
- # Move from `sources` to `destination`
18
+ # Move `sources` to a `destination` directory.
19
19
  #
20
- # The path is not moved if a file already exists at the destination with the same name. A warning is logged instead.
20
+ # Movement is only allowed to directories that already exist. If your intention is to rename, see the `rename` method.
21
21
  #
22
22
  # ## Examples
23
23
  #
@@ -32,15 +32,47 @@ module Maid::Tools
32
32
  def move(sources, destination)
33
33
  destination = expand(destination)
34
34
 
35
- expand_all(sources).each do |source|
36
- target = File.join(destination, File.basename(source))
37
-
38
- unless File.exist?(target)
39
- log("mv #{ sh_escape(source) } #{ sh_escape(destination) }")
35
+ if File.directory?(destination)
36
+ expand_all(sources).each do |source|
37
+ log("move #{ sh_escape(source) } #{ sh_escape(destination) }")
40
38
  FileUtils.mv(source, destination, @file_options)
41
- else
42
- warn("skipping #{ sh_escape(source) } because #{ sh_escape(target) } already exists")
43
39
  end
40
+ else
41
+ # Unix `mv` warns about the target not being a directory with multiple sources. Maid checks the same.
42
+ warn("skipping move because #{ sh_escape(destination) } is not a directory (use 'mkdir' to create first, or use 'rename')")
43
+ end
44
+ end
45
+
46
+ # Rename a single file.
47
+ #
48
+ # Any directories needed in order to complete the rename are made automatically.
49
+ #
50
+ # Overwriting is not allowed; it logs a warning. If overwriting is desired, use `remove` to delete the file first, then use `rename`.
51
+ #
52
+ # ## Examples
53
+ #
54
+ # Simple rename:
55
+ #
56
+ # rename('foo.zip', 'baz.zip') # "foo.zip" becomes "baz.zip"
57
+ #
58
+ # Rename needing directories:
59
+ #
60
+ # rename('foo.zip', 'bar/baz.zip') # "bar" is created, "foo.zip" becomes "baz.zip" within "bar"
61
+ #
62
+ # Attempting to overwrite:
63
+ #
64
+ # rename('foo.zip', 'existing.zip') # "skipping move of..."
65
+ def rename(source, destination)
66
+ source = expand(source)
67
+ destination = expand(destination)
68
+
69
+ mkdir(File.dirname(destination))
70
+
71
+ if File.exist?(destination)
72
+ warn("skipping rename of #{ sh_escape(source) } to #{ sh_escape(destination) } because it would overwrite")
73
+ else
74
+ log("rename #{ sh_escape(source) } #{ sh_escape(destination) }")
75
+ FileUtils.mv(source, destination, @file_options)
44
76
  end
45
77
  end
46
78
 
@@ -99,7 +131,7 @@ module Maid::Tools
99
131
 
100
132
  if File.exist?(path)
101
133
  if File.exist?(target)
102
- move(path, safe_trash_path)
134
+ rename(path, safe_trash_path)
103
135
  else
104
136
  move(path, @trash_path)
105
137
  end
@@ -244,7 +276,7 @@ module Maid::Tools
244
276
  #
245
277
  # locate('foo.zip') # => ['/a/foo.zip', '/b/foo.zip']
246
278
  def locate(name)
247
- cmd("#{Maid::Platform::Commands.locate} #{ sh_escape(name) }").split("\n")
279
+ cmd("mdfind -name #{ sh_escape(name) }").split("\n")
248
280
  end
249
281
 
250
282
  # [Mac OS X] Use Spotlight metadata to determine the site from which a file was downloaded.
data/lib/maid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maid
2
- VERSION = '0.2.3.alpha.1'
2
+ VERSION = '0.3.0.beta.1'
3
3
  end
@@ -77,7 +77,7 @@ module Maid
77
77
  end
78
78
 
79
79
  it 'is mapped as --version' do
80
- App.start(['--version']).should == @app.version
80
+ # TODO: Test via Rspec (it's only in the smoke test script for now)
81
81
  end
82
82
 
83
83
  context 'with the "long" option' do
@@ -189,11 +189,11 @@ module Maid
189
189
  end
190
190
 
191
191
  it 'should report `not-a-real-command` as not being a supported command' do
192
- lambda { @maid.cmd('not-a-real-command arg1 arg2') }.should raise_error(NotImplementedError)
192
+ lambda { @maid.cmd('not-a-real-command arg1 arg2') }.should raise_error(ArgumentError)
193
193
  end
194
194
 
195
195
  it 'should report `echo` as a real command' do
196
- lambda { @maid.cmd('echo .') }.should_not raise_error(NotImplementedError)
196
+ lambda { @maid.cmd('echo .') }.should_not raise_error(ArgumentError)
197
197
  end
198
198
  end
199
199
  end
@@ -25,10 +25,6 @@ module Maid
25
25
  it 'is not identified as OS X' do
26
26
  subject.osx?.should be_false
27
27
  end
28
-
29
- it 'locate is "locate"' do
30
- Platform::Commands.locate.should match(/locate/)
31
- end
32
28
  end
33
29
 
34
30
  context 'when running on Mac OS X' do
@@ -43,10 +39,6 @@ module Maid
43
39
  it 'is identified as OS X' do
44
40
  subject.osx?.should be_true
45
41
  end
46
-
47
- it 'locate is "mdfind"' do
48
- Platform::Commands.locate.should match(/mdfind/)
49
- end
50
42
  end
51
43
  end
52
44
  end
@@ -41,13 +41,6 @@ module Maid
41
41
  @maid.move(@src_file, @dst_dir)
42
42
  end
43
43
 
44
- it 'should not move if the target already exists' do
45
- FileUtils.touch(@dst_dir + @file_name)
46
- @logger.should_receive(:warn)
47
-
48
- @maid.move(@src_file, @dst_dir)
49
- end
50
-
51
44
  it 'should handle multiple from paths' do
52
45
  second_src_file = @src_dir + (second_file_name = 'bar.zip')
53
46
  FileUtils.touch(second_src_file)
@@ -57,6 +50,60 @@ module Maid
57
50
  File.exist?(@dst_dir + @file_name).should be_true
58
51
  File.exist?(@dst_dir + second_file_name).should be_true
59
52
  end
53
+
54
+ context 'given the destination directory does not exist' do
55
+ before do
56
+ FileUtils.rmdir(@dst_dir)
57
+ end
58
+
59
+ it 'does not overwrite when moving' do
60
+ FileUtils.should_not_receive(:mv)
61
+ @logger.should_receive(:warn).once
62
+
63
+ another_file = "#@src_file.1"
64
+ @maid.move([@src_file, another_file], @dst_dir)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#rename' do
70
+ before do
71
+ @src_file = (@src_dir = '~/Source/') + (@file_name = 'foo.zip')
72
+ FileUtils.mkdir_p(@src_dir)
73
+ FileUtils.touch(@src_file)
74
+ @expanded_src_name = "#@home/Source/foo.zip"
75
+
76
+ @dst_name = '~/Destination/bar.zip'
77
+ @expanded_dst_dir = "#@home/Destination/"
78
+ @expanded_dst_name = "#@home/Destination/bar.zip"
79
+ end
80
+
81
+ it 'creates needed directories' do
82
+ File.directory?(@expanded_dst_dir).should be_false
83
+ @maid.rename(@src_file, @dst_name)
84
+ File.directory?(@expanded_dst_dir).should be_true
85
+ end
86
+
87
+ it 'moves the file from the source to the destination' do
88
+ File.exists?(@expanded_src_name).should be_true
89
+ File.exists?(@expanded_dst_name).should be_false
90
+ @maid.rename(@src_file, @dst_name)
91
+ File.exists?(@expanded_src_name).should be_false
92
+ File.exists?(@expanded_dst_name).should be_true
93
+ end
94
+
95
+ context 'given the target already exists' do
96
+ before do
97
+ FileUtils.mkdir_p(@expanded_dst_dir)
98
+ FileUtils.touch(@expanded_dst_name)
99
+ end
100
+
101
+ it 'does not move' do
102
+ @logger.should_receive(:warn)
103
+
104
+ @maid.rename(@src_file, @dst_name)
105
+ end
106
+ end
60
107
  end
61
108
 
62
109
  describe '#trash' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.alpha.1
4
+ version: 0.3.0.beta.1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: escape
16
- requirement: &15830020 !ruby/object:Gem::Requirement
16
+ requirement: &13576940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.1.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *15830020
27
+ version_requirements: *13576940
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
- requirement: &15829220 !ruby/object:Gem::Requirement
30
+ requirement: &13576140 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: 0.18.0
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *15829220
41
+ version_requirements: *13576140
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: deprecated
44
- requirement: &15828480 !ruby/object:Gem::Requirement
44
+ requirement: &13575420 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: 3.0.0
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *15828480
52
+ version_requirements: *13575420
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: ohai
55
- requirement: &15827940 !ruby/object:Gem::Requirement
55
+ requirement: &13574920 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -63,10 +63,10 @@ dependencies:
63
63
  version: 6.17.0
64
64
  type: :runtime
65
65
  prerelease: false
66
- version_requirements: *15827940
66
+ version_requirements: *13574920
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: xdg
69
- requirement: &15827100 !ruby/object:Gem::Requirement
69
+ requirement: &13574200 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
72
  - - ~>
@@ -74,10 +74,10 @@ dependencies:
74
74
  version: 2.2.3
75
75
  type: :runtime
76
76
  prerelease: false
77
- version_requirements: *15827100
77
+ version_requirements: *13574200
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: fakefs
80
- requirement: &15826520 !ruby/object:Gem::Requirement
80
+ requirement: &13573740 !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
@@ -85,10 +85,10 @@ dependencies:
85
85
  version: 0.4.2
86
86
  type: :development
87
87
  prerelease: false
88
- version_requirements: *15826520
88
+ version_requirements: *13573740
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: guard
91
- requirement: &15825380 !ruby/object:Gem::Requirement
91
+ requirement: &13573280 !ruby/object:Gem::Requirement
92
92
  none: false
93
93
  requirements:
94
94
  - - ~>
@@ -96,10 +96,10 @@ dependencies:
96
96
  version: 1.6.2
97
97
  type: :development
98
98
  prerelease: false
99
- version_requirements: *15825380
99
+ version_requirements: *13573280
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: guard-rspec
102
- requirement: &15824120 !ruby/object:Gem::Requirement
102
+ requirement: &13572780 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
105
  - - ~>
@@ -107,10 +107,10 @@ dependencies:
107
107
  version: 2.4.0
108
108
  type: :development
109
109
  prerelease: false
110
- version_requirements: *15824120
110
+ version_requirements: *13572780
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
- requirement: &15823480 !ruby/object:Gem::Requirement
113
+ requirement: &13572300 !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements:
116
116
  - - ~>
@@ -118,10 +118,10 @@ dependencies:
118
118
  version: 10.0.3
119
119
  type: :development
120
120
  prerelease: false
121
- version_requirements: *15823480
121
+ version_requirements: *13572300
122
122
  - !ruby/object:Gem::Dependency
123
123
  name: redcarpet
124
- requirement: &15822800 !ruby/object:Gem::Requirement
124
+ requirement: &13571740 !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
127
127
  - - ~>
@@ -129,10 +129,10 @@ dependencies:
129
129
  version: 2.2.2
130
130
  type: :development
131
131
  prerelease: false
132
- version_requirements: *15822800
132
+ version_requirements: *13571740
133
133
  - !ruby/object:Gem::Dependency
134
134
  name: rspec
135
- requirement: &15720280 !ruby/object:Gem::Requirement
135
+ requirement: &13571220 !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements:
138
138
  - - ~>
@@ -140,10 +140,10 @@ dependencies:
140
140
  version: 2.12.0
141
141
  type: :development
142
142
  prerelease: false
143
- version_requirements: *15720280
143
+ version_requirements: *13571220
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: timecop
146
- requirement: &15718860 !ruby/object:Gem::Requirement
146
+ requirement: &13570540 !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements:
149
149
  - - ~>
@@ -151,10 +151,10 @@ dependencies:
151
151
  version: 0.5.9.1
152
152
  type: :development
153
153
  prerelease: false
154
- version_requirements: *15718860
154
+ version_requirements: *13570540
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: yard
157
- requirement: &15717940 !ruby/object:Gem::Requirement
157
+ requirement: &13130520 !ruby/object:Gem::Requirement
158
158
  none: false
159
159
  requirements:
160
160
  - - ~>
@@ -162,10 +162,10 @@ dependencies:
162
162
  version: 0.8.4
163
163
  type: :development
164
164
  prerelease: false
165
- version_requirements: *15717940
165
+ version_requirements: *13130520
166
166
  - !ruby/object:Gem::Dependency
167
167
  name: rb-inotify
168
- requirement: &15717240 !ruby/object:Gem::Requirement
168
+ requirement: &13129900 !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
171
171
  - - ~>
@@ -173,10 +173,10 @@ dependencies:
173
173
  version: 0.9.0
174
174
  type: :development
175
175
  prerelease: false
176
- version_requirements: *15717240
176
+ version_requirements: *13129900
177
177
  - !ruby/object:Gem::Dependency
178
178
  name: rb-fsevent
179
- requirement: &15716540 !ruby/object:Gem::Requirement
179
+ requirement: &13128980 !ruby/object:Gem::Requirement
180
180
  none: false
181
181
  requirements:
182
182
  - - ~>
@@ -184,7 +184,7 @@ dependencies:
184
184
  version: 0.9.2
185
185
  type: :development
186
186
  prerelease: false
187
- version_requirements: *15716540
187
+ version_requirements: *13128980
188
188
  description: Be lazy. Let Maid clean up after you, based on rules you define. Think
189
189
  of it as "Hazel for hackers".
190
190
  email: