remote_files 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remote_files/abstract_store.rb +4 -0
- data/lib/remote_files/configuration.rb +1 -2
- data/lib/remote_files/file.rb +20 -1
- data/lib/remote_files/file_store.rb +4 -0
- data/lib/remote_files/fog_store.rb +10 -6
- data/lib/remote_files/memory_store.rb +4 -0
- data/lib/remote_files/version.rb +1 -1
- data/test/file_store_test.rb +6 -0
- data/test/file_test.rb +44 -2
- data/test/fog_store_test.rb +6 -0
- data/test/memory_store_test.rb +7 -0
- metadata +3 -3
@@ -114,8 +114,7 @@ module RemoteFiles
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def synchronize!(file)
|
117
|
-
file.missing_stores.each do |
|
118
|
-
store = lookup_store(store_identifier)
|
117
|
+
file.missing_stores.each do |store|
|
119
118
|
store.store!(file)
|
120
119
|
file.stored_in << store.identifier
|
121
120
|
end
|
data/lib/remote_files/file.rb
CHANGED
@@ -37,8 +37,12 @@ module RemoteFiles
|
|
37
37
|
missing_stores.empty?
|
38
38
|
end
|
39
39
|
|
40
|
+
def stores
|
41
|
+
@stored_in.map { |store_id| configuration.lookup_store(store_id) }
|
42
|
+
end
|
43
|
+
|
40
44
|
def missing_stores
|
41
|
-
configuration.stores
|
45
|
+
configuration.stores - stores
|
42
46
|
end
|
43
47
|
|
44
48
|
def url(store_identifier = nil)
|
@@ -55,6 +59,21 @@ module RemoteFiles
|
|
55
59
|
url(prioritized_stores[0])
|
56
60
|
end
|
57
61
|
|
62
|
+
def retrieve!
|
63
|
+
stores.each do |store|
|
64
|
+
begin
|
65
|
+
file = store.retrieve!(identifier)
|
66
|
+
next unless file
|
67
|
+
@content = file.content
|
68
|
+
@content_type = file.content_type
|
69
|
+
return true
|
70
|
+
rescue Error => e
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
raise NotFoundError
|
75
|
+
end
|
76
|
+
|
58
77
|
def store!
|
59
78
|
configuration.store!(self)
|
60
79
|
end
|
@@ -35,9 +35,9 @@ module RemoteFiles
|
|
35
35
|
def url(identifier)
|
36
36
|
case options[:provider]
|
37
37
|
when 'AWS'
|
38
|
-
"https://s3.amazonaws.com/#{
|
38
|
+
"https://s3.amazonaws.com/#{directory_name}/#{Fog::AWS.escape(identifier)}"
|
39
39
|
when 'Rackspace'
|
40
|
-
"https://storage.cloudfiles.com/#{
|
40
|
+
"https://storage.cloudfiles.com/#{directory_name}/#{Fog::Rackspace.escape(identifier, '/')}"
|
41
41
|
else
|
42
42
|
raise "#{self.class.name}#url was not implemented for the #{options[:provider]} provider"
|
43
43
|
end
|
@@ -46,9 +46,9 @@ module RemoteFiles
|
|
46
46
|
def url_matcher
|
47
47
|
@url_matcher ||= case options[:provider]
|
48
48
|
when 'AWS'
|
49
|
-
/https?:\/\/s3[^\.]*.amazonaws.com\/#{
|
49
|
+
/https?:\/\/s3[^\.]*.amazonaws.com\/#{directory_name}\/(.*)/
|
50
50
|
when 'Rackspace'
|
51
|
-
/https?:\/\/storage.cloudfiles.com\/#{
|
51
|
+
/https?:\/\/storage.cloudfiles.com\/#{directory_name}\/(.*)/
|
52
52
|
else
|
53
53
|
raise "#{self.class.name}#url_matcher was not implemented for the #{options[:provider]} provider"
|
54
54
|
end
|
@@ -65,6 +65,10 @@ module RemoteFiles
|
|
65
65
|
@connection ||= Fog::Storage.new(connection_options)
|
66
66
|
end
|
67
67
|
|
68
|
+
def directory_name
|
69
|
+
options[:directory]
|
70
|
+
end
|
71
|
+
|
68
72
|
def directory
|
69
73
|
@directory ||= lookup_directory || create_directory
|
70
74
|
end
|
@@ -72,12 +76,12 @@ module RemoteFiles
|
|
72
76
|
protected
|
73
77
|
|
74
78
|
def lookup_directory
|
75
|
-
connection.directories.get(
|
79
|
+
connection.directories.get(directory_name)
|
76
80
|
end
|
77
81
|
|
78
82
|
def create_directory
|
79
83
|
connection.directories.new(
|
80
|
-
:key =>
|
84
|
+
:key => directory_name,
|
81
85
|
:public => options[:public]
|
82
86
|
).tap do |dir|
|
83
87
|
dir.save
|
data/lib/remote_files/version.rb
CHANGED
data/test/file_store_test.rb
CHANGED
data/test/file_test.rb
CHANGED
@@ -37,10 +37,17 @@ describe RemoteFiles::File do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
describe '#stores' do
|
41
|
+
it 'should give an array of stores where the file is stored' do
|
42
|
+
@file.stored_in.replace([:s3])
|
43
|
+
@file.stores.must_equal([@s3])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
describe '#missing_stores' do
|
41
|
-
it 'should give an array of
|
48
|
+
it 'should give an array of stores where the file is not stored' do
|
42
49
|
@file.stored_in.replace([:s3])
|
43
|
-
@file.missing_stores.must_equal([
|
50
|
+
@file.missing_stores.must_equal([@cf])
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
@@ -103,4 +110,39 @@ describe RemoteFiles::File do
|
|
103
110
|
@file.delete!
|
104
111
|
end
|
105
112
|
end
|
113
|
+
|
114
|
+
describe '#retrieve!' do
|
115
|
+
before do
|
116
|
+
@file_with_content = RemoteFiles::File.new('identifier', :content => 'content', :content_type => 'content_type')
|
117
|
+
|
118
|
+
@store = stub
|
119
|
+
@file.stubs(:stores).returns([@store])
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'when the file is found' do
|
123
|
+
before do
|
124
|
+
@store.expects(:retrieve!).returns(@file_with_content)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'fills in the content and content_type' do
|
128
|
+
@file.content.must_be_nil
|
129
|
+
@file.content_type.must_be_nil
|
130
|
+
|
131
|
+
@file.retrieve!
|
132
|
+
|
133
|
+
@file.content.must_equal 'content'
|
134
|
+
@file.content_type.must_equal 'content_type'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'when the file is not found' do
|
139
|
+
before do
|
140
|
+
@store.expects(:retrieve!).returns(nil)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'raises a NotFoundError' do
|
144
|
+
proc { @file.retrieve! }.must_raise(RemoteFiles::NotFoundError)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
106
148
|
end
|
data/test/fog_store_test.rb
CHANGED
data/test/memory_store_test.rb
CHANGED
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.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -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: 708350776970309851
|
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: 708350776970309851
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
163
|
rubygems_version: 1.8.24
|