vtools 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vtools.rb +1 -0
- data/lib/vtools/converter.rb +1 -3
- data/lib/vtools/shared_methods.rb +10 -3
- data/lib/vtools/thumbnailer.rb +0 -1
- data/lib/vtools/version.rb +1 -1
- data/spec/shared_methods_spec.rb +109 -67
- data/spec/spec_helper.rb +0 -1
- metadata +7 -7
data/lib/vtools.rb
CHANGED
data/lib/vtools/converter.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding: binary -*-
|
2
2
|
|
3
3
|
module VTools
|
4
|
-
|
5
4
|
# shared methods
|
6
5
|
module SharedMethods
|
7
6
|
# both static & instance bindings
|
@@ -83,14 +82,22 @@ module VTools
|
|
83
82
|
generator = instance_exec(file_name, &generator).to_s if generator.is_a? Proc
|
84
83
|
rescue => e
|
85
84
|
generator = nil
|
86
|
-
raise ConfigError, "Path generator error (#{e})"
|
85
|
+
raise ConfigError, "Path generator error: (#{e})"
|
87
86
|
end
|
88
87
|
|
89
88
|
storage = CONFIG[:"#{scope}_storage"].to_s
|
90
89
|
storage += "/" unless storage.empty?
|
91
90
|
storage += generator || ""
|
92
91
|
|
93
|
-
(!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/+#, '/').gsub(%r#/$#, '')
|
92
|
+
path = (!storage || storage.empty? ? CONFIG[:PWD] : storage).to_s.strip.gsub(%r#/+#, '/').gsub(%r#/$#, '')
|
93
|
+
|
94
|
+
# generate path
|
95
|
+
begin
|
96
|
+
FileUtils.mkdir_p path, :mode => 775
|
97
|
+
rescue => e
|
98
|
+
raise FileError, "Path generator error: #{e}"
|
99
|
+
end unless File.exists?(path)
|
100
|
+
path
|
94
101
|
end
|
95
102
|
|
96
103
|
# path generator setter
|
data/lib/vtools/thumbnailer.rb
CHANGED
data/lib/vtools/version.rb
CHANGED
data/spec/shared_methods_spec.rb
CHANGED
@@ -140,7 +140,7 @@ describe VTools::SharedMethods do
|
|
140
140
|
VTools::CONFIG[:test_index] = "test.value"
|
141
141
|
|
142
142
|
@class.config(:test_index).should == "test.value"
|
143
|
-
@class.config(:nonexistent_index).
|
143
|
+
@class.config(:nonexistent_index).should_not be
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -182,93 +182,135 @@ describe VTools::SharedMethods do
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
-
context "
|
185
|
+
context "paths generator" do
|
186
186
|
|
187
|
-
|
188
|
-
VTools::CONFIG[:video_storage] =
|
189
|
-
VTools::CONFIG[:thumb_storage] =
|
187
|
+
before do
|
188
|
+
VTools::CONFIG[:video_storage] = nil
|
189
|
+
VTools::CONFIG[:thumb_storage] = nil
|
190
|
+
VTools::CONFIG[:thumb_path_generator] = nil
|
191
|
+
VTools::CONFIG[:video_path_generator] = nil
|
192
|
+
end
|
190
193
|
|
191
|
-
|
192
|
-
@class.generate_path("test.filename", "thumb").should == "/thumb/path"
|
194
|
+
context "#generate_path" do
|
193
195
|
|
194
|
-
|
196
|
+
before do
|
197
|
+
File.stub(:exists?).and_return(true)
|
198
|
+
VTools::CONFIG[:PWD] = ""
|
199
|
+
end
|
195
200
|
|
196
|
-
|
197
|
-
|
201
|
+
context "using string path from" do
|
202
|
+
it "config storage" do
|
203
|
+
VTools::CONFIG[:video_storage] = "test/path/"
|
204
|
+
VTools::CONFIG[:thumb_storage] = "/thumb/path"
|
198
205
|
|
199
|
-
|
200
|
-
|
206
|
+
@class.generate_path("test.filename").should == "test/path"
|
207
|
+
@class.generate_path("test.filename", "thumb").should == "/thumb/path"
|
208
|
+
end
|
201
209
|
|
202
|
-
|
203
|
-
end
|
210
|
+
it "CONFIG[:PWD]" do
|
204
211
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
212
|
+
VTools::CONFIG[:thumb_storage] = ''
|
213
|
+
VTools::CONFIG[:PWD] = "test/pwd"
|
214
|
+
@class.generate_path("test.filename", "thumb").should == "test/pwd"
|
215
|
+
@class.generate_path("test.filename").should == "test/pwd"
|
216
|
+
end
|
217
|
+
|
218
|
+
it "empty set" do
|
219
|
+
@class.generate_path("test.filename").should == ""
|
220
|
+
end
|
210
221
|
end
|
211
222
|
|
212
|
-
|
213
|
-
|
214
|
-
|
223
|
+
context "using callback" do
|
224
|
+
|
225
|
+
let(:failed_prc) { proc { CONFIG[:thumb_storage] } }
|
226
|
+
let(:prc) {
|
227
|
+
proc do |file|
|
228
|
+
file.should == "test.filename"
|
229
|
+
self.class.should == Tested
|
230
|
+
"test/path"
|
231
|
+
end
|
232
|
+
}
|
233
|
+
|
234
|
+
|
235
|
+
it "executes block" do
|
236
|
+
VTools::CONFIG[:video_storage] = '/root/'
|
237
|
+
VTools::CONFIG[:video_path_generator] = prc
|
238
|
+
@class.generate_path("test.filename", "video").should == "/root/test/path"
|
239
|
+
|
240
|
+
VTools::CONFIG[:thumb_storage] = 'root'
|
241
|
+
VTools::CONFIG[:thumb_path_generator] = prc
|
242
|
+
@class.generate_path("test.filename", "thumb").should == "root/test/path"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "raises exception on invalid block" do
|
246
|
+
VTools::CONFIG[:video_path_generator] = failed_prc
|
247
|
+
expect do
|
248
|
+
@class.generate_path("test.filename", "video")
|
249
|
+
end.to raise_error VTools::ConfigError, /Path generator error/
|
250
|
+
end
|
251
|
+
end
|
215
252
|
|
216
|
-
|
217
|
-
VTools::CONFIG[:thumb_path_generator] = prc
|
218
|
-
@class.generate_path("test.filename", "thumb").should == "root/test/path"
|
219
|
-
end
|
253
|
+
context "creates path" do
|
220
254
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
255
|
+
before do
|
256
|
+
File.stub(:exists?).and_return(false)
|
257
|
+
VTools::CONFIG[:video_storage] = "/root/"
|
258
|
+
end
|
225
259
|
|
226
|
-
|
227
|
-
|
228
|
-
@class.generate_path("test.filename", "video").should == "/root/test/path"
|
229
|
-
end.to raise_error VTools::ConfigError, /Path generator error/
|
230
|
-
end
|
231
|
-
end
|
260
|
+
it "successfull" do
|
261
|
+
FileUtils.should_receive(:mkdir_p).and_return(nil)
|
232
262
|
|
233
|
-
|
263
|
+
expect do
|
264
|
+
@class.generate_path("test.filename").should == "/root"
|
265
|
+
end.to_not raise_error
|
266
|
+
end
|
234
267
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
268
|
+
it "with error" do
|
269
|
+
FileUtils.should_receive(:mkdir_p).and_return do
|
270
|
+
raise Errno::EACCES, "Permission denied"
|
271
|
+
end
|
272
|
+
|
273
|
+
expect do
|
274
|
+
@class.generate_path("test.filename")
|
275
|
+
end.to raise_error VTools::FileError, /Path generator error: /
|
276
|
+
end
|
277
|
+
end
|
240
278
|
end
|
241
279
|
|
242
|
-
|
280
|
+
context "#path_generator appended to" do
|
243
281
|
|
244
|
-
|
245
|
-
@class.path_generator "thumb", &block
|
246
|
-
VTools::CONFIG[:thumb_path_generator].should == block
|
247
|
-
VTools::CONFIG[:video_path_generator].should be nil
|
248
|
-
end
|
282
|
+
let(:block_stub) { proc {nil} }
|
249
283
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
284
|
+
it "thumbs only" do
|
285
|
+
@class.path_generator "thumbs path", &block_stub
|
286
|
+
VTools::CONFIG[:thumb_path_generator].should == block_stub
|
287
|
+
VTools::CONFIG[:video_path_generator].should_not be
|
288
|
+
end
|
255
289
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
290
|
+
it "thumbs path only (invalid placeholedr given)" do
|
291
|
+
@class.path_generator "invalid", &block_stub
|
292
|
+
VTools::CONFIG[:thumb_path_generator].should == block_stub
|
293
|
+
VTools::CONFIG[:video_path_generator].should_not be
|
294
|
+
end
|
261
295
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
296
|
+
it "video path" do
|
297
|
+
@class.path_generator "video", &block_stub
|
298
|
+
VTools::CONFIG[:video_path_generator].should == block_stub
|
299
|
+
VTools::CONFIG[:thumb_path_generator].should_not be
|
300
|
+
end
|
301
|
+
|
302
|
+
it "both paths (default)" do
|
303
|
+
@class.path_generator &block_stub
|
304
|
+
[:video_path_generator, :thumb_path_generator].each do |index|
|
305
|
+
VTools::CONFIG[index].should == block_stub
|
306
|
+
end
|
307
|
+
end
|
267
308
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
309
|
+
it "nothing" do
|
310
|
+
@class.path_generator
|
311
|
+
VTools::CONFIG[:video_path_generator].should_not be
|
312
|
+
VTools::CONFIG[:thumb_path_generator].should_not be
|
313
|
+
end
|
272
314
|
end
|
273
315
|
end
|
274
316
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-14 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: daemons
|
16
|
-
requirement: &
|
16
|
+
requirement: &71995340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.1.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *71995340
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &71995150 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *71995150
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &71994920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *71994920
|
47
47
|
description: FFMPEG & FFMPEGTHUMBNAILER based video processor. Permits to generate
|
48
48
|
thumbs and encode/edit video. Can be started as daemon.
|
49
49
|
email: v.tofir@gmail.com
|