remote_files 1.3.1 → 1.3.2
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/lib/remote_files.rb +15 -1
- data/lib/remote_files/abstract_store.rb +2 -2
- data/lib/remote_files/configuration.rb +1 -1
- data/lib/remote_files/file.rb +5 -1
- data/lib/remote_files/resque_job.rb +16 -2
- data/lib/remote_files/version.rb +1 -1
- data/test/configuration_test.rb +8 -0
- data/test/file_test.rb +1 -1
- data/test/resque_job_test.rb +55 -27
- metadata +4 -4
data/lib/remote_files.rb
CHANGED
@@ -45,7 +45,7 @@ module RemoteFiles
|
|
45
45
|
if @synchronize_stores
|
46
46
|
@synchronize_stores.call(file)
|
47
47
|
else
|
48
|
-
synchronize!(file)
|
48
|
+
file.synchronize!(file)
|
49
49
|
end
|
50
50
|
elsif block_given?
|
51
51
|
@synchronize_stores = block
|
@@ -53,4 +53,18 @@ module RemoteFiles
|
|
53
53
|
raise "invalid call to RemoteFiles.synchronize_stores"
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
def self.delete_file(file = nil, &block)
|
58
|
+
if file
|
59
|
+
if @delete_file
|
60
|
+
@delete_file.call(file)
|
61
|
+
else
|
62
|
+
file.delete_now!(file)
|
63
|
+
end
|
64
|
+
elsif block_given?
|
65
|
+
@delete_file = block
|
66
|
+
else
|
67
|
+
raise "invalid call to RemoteFiles.delete_file"
|
68
|
+
end
|
69
|
+
end
|
56
70
|
end
|
@@ -34,14 +34,14 @@ module RemoteFiles
|
|
34
34
|
raise "You need to implement #{self.class.name}:#url_matcher"
|
35
35
|
end
|
36
36
|
|
37
|
-
def file_from_url(url)
|
37
|
+
def file_from_url(url, options = {})
|
38
38
|
matched = url_matcher.match(url)
|
39
39
|
|
40
40
|
return nil unless matched
|
41
41
|
|
42
42
|
file_identifier = matched[1]
|
43
43
|
|
44
|
-
RemoteFiles::File.new(file_identifier, :stored_in => [identifier])
|
44
|
+
RemoteFiles::File.new(file_identifier, options.merge(:stored_in => [identifier]))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/remote_files/file.rb
CHANGED
@@ -63,7 +63,7 @@ module RemoteFiles
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def delete!
|
66
|
-
|
66
|
+
delete_now!
|
67
67
|
end
|
68
68
|
|
69
69
|
def delete
|
@@ -74,5 +74,9 @@ module RemoteFiles
|
|
74
74
|
false
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
def delete_now!
|
79
|
+
configuration.delete!(self)
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
@@ -4,12 +4,26 @@ require 'resque'
|
|
4
4
|
module RemoteFiles
|
5
5
|
class ResqueJob
|
6
6
|
def self.perform(options)
|
7
|
+
action = options.delete(:_action)
|
8
|
+
|
7
9
|
file = RemoteFiles::File.new(options.delete(:identifier), options)
|
8
|
-
|
10
|
+
|
11
|
+
case action
|
12
|
+
when :synchronize
|
13
|
+
file.synchronize!
|
14
|
+
when :delete
|
15
|
+
file.delete_now!(file)
|
16
|
+
else
|
17
|
+
raise "unknown action #{action.inspect}"
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
|
12
22
|
synchronize_stores do |file|
|
13
|
-
Resque.enqueue(ResqueJob, file.options)
|
23
|
+
Resque.enqueue(ResqueJob, file.options.merge(:_action => :synchronize))
|
24
|
+
end
|
25
|
+
|
26
|
+
delete_file do |file|
|
27
|
+
Resque.enqueue(ResqueJob, file.options.merge(:_action => :delete))
|
14
28
|
end
|
15
29
|
end
|
data/lib/remote_files/version.rb
CHANGED
data/test/configuration_test.rb
CHANGED
@@ -175,4 +175,12 @@ describe RemoteFiles::Configuration do
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
describe '#file_from_url' do
|
179
|
+
it 'should return a file from this configuration' do
|
180
|
+
file = @configuration.file_from_url('memory://mock2/foo')
|
181
|
+
assert file
|
182
|
+
file.configuration.must_equal @configuration
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
178
186
|
end
|
data/test/file_test.rb
CHANGED
@@ -84,7 +84,7 @@ describe RemoteFiles::File do
|
|
84
84
|
describe '::from_url' do
|
85
85
|
it 'should return a file from the first store that matches' do
|
86
86
|
url = 'http://something'
|
87
|
-
@cf.expects(:file_from_url).with(url).returns(@file)
|
87
|
+
@cf.expects(:file_from_url).with(url, :configuration => :default).returns(@file)
|
88
88
|
assert_equal @file, RemoteFiles::File.from_url(url)
|
89
89
|
end
|
90
90
|
end
|
data/test/resque_job_test.rb
CHANGED
@@ -3,45 +3,73 @@ require 'remote_files/resque_job'
|
|
3
3
|
|
4
4
|
describe RemoteFiles::ResqueJob do
|
5
5
|
describe 'loading the implementation file' do
|
6
|
-
before
|
6
|
+
before do
|
7
|
+
@file = RemoteFiles::File.new('identifier',
|
8
|
+
:content_type => 'text/plain',
|
9
|
+
:content => 'content',
|
10
|
+
:stored_in => [:s3],
|
11
|
+
:foo => :bar
|
12
|
+
)
|
13
|
+
|
14
|
+
load 'remote_files/resque_job.rb'
|
15
|
+
end
|
7
16
|
|
8
17
|
it 'should setup the right synchronize_stores hook' do
|
9
|
-
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:stored_in
|
13
|
-
:foo
|
18
|
+
Resque.expects(:enqueue).with(RemoteFiles::ResqueJob,
|
19
|
+
:identifier => 'identifier',
|
20
|
+
:content_type => 'text/plain',
|
21
|
+
:stored_in => [:s3],
|
22
|
+
:foo => :bar,
|
23
|
+
:configuration => :default,
|
24
|
+
:_action => :synchronize
|
14
25
|
)
|
15
26
|
|
27
|
+
RemoteFiles.synchronize_stores(@file)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should setup the right delete_file hook' do
|
16
31
|
Resque.expects(:enqueue).with(RemoteFiles::ResqueJob,
|
17
|
-
:identifier
|
18
|
-
:content_type
|
19
|
-
:stored_in
|
20
|
-
:foo
|
21
|
-
:configuration => :default
|
32
|
+
:identifier => 'identifier',
|
33
|
+
:content_type => 'text/plain',
|
34
|
+
:stored_in => [:s3],
|
35
|
+
:foo => :bar,
|
36
|
+
:configuration => :default,
|
37
|
+
:_action => :delete
|
22
38
|
)
|
23
39
|
|
24
|
-
RemoteFiles.
|
40
|
+
RemoteFiles.delete_file(@file)
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
describe "running the job" do
|
45
|
+
before do
|
46
|
+
@options = {
|
47
|
+
:identifier => 'identifier',
|
48
|
+
:content_type => 'text/plain',
|
49
|
+
:stored_in => [:s3],
|
50
|
+
:foo => :bar
|
51
|
+
}
|
35
52
|
|
36
|
-
|
37
|
-
file.expects(:synchronize!)
|
53
|
+
@file = stub
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
55
|
+
RemoteFiles::File.expects(:new).with('identifier',
|
56
|
+
:content_type => 'text/plain',
|
57
|
+
:stored_in => [:s3],
|
58
|
+
:foo => :bar
|
59
|
+
).returns(@file)
|
60
|
+
end
|
44
61
|
|
45
|
-
|
62
|
+
it 'should call #synchronize! on the reconstructed file when asked to' do
|
63
|
+
@file.expects(:synchronize!)
|
64
|
+
|
65
|
+
RemoteFiles::ResqueJob.perform(@options.merge(:_action => :synchronize))
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should call #synchronize! on the reconstructed file when asked to' do
|
69
|
+
@file.expects(:delete_now!)
|
70
|
+
|
71
|
+
RemoteFiles::ResqueJob.perform(@options.merge(:_action => :delete))
|
72
|
+
end
|
46
73
|
end
|
74
|
+
|
47
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
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-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: 2988257809019653015
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash:
|
160
|
+
hash: 2988257809019653015
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
163
|
rubygems_version: 1.8.24
|