mingle-storage 0.0.13 → 0.1.0
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.
- checksums.yaml +5 -5
- data/lib/storage.rb +1 -1
- data/lib/storage/s3_store.rb +24 -25
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3657d919376dec9d78341d9dc72d91319c9c6b3880a79ddc2b09eb4c2d8c20fa
|
4
|
+
data.tar.gz: 5804abb38219d867467fdafe4c379b4a3639ea3ee1921193d3d902ce0a07099e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79eda50792dbcf9e70fe5a5c18079b09ad9b6394389df3b56e35667869e1debf56ee1b8d4bf665eacfa2799581bc1519c01677346ced7e8e4ce2e551950637e8
|
7
|
+
data.tar.gz: 5ec411b3f14451e04ed1b25aab3c507b17e3e415be6e6fc8b959388e928d3049bf3cae9acdd67ad1e12e4d6afd0ae8d1feb243830be669c6a0810ea2b805f47f
|
data/lib/storage.rb
CHANGED
data/lib/storage/s3_store.rb
CHANGED
@@ -125,52 +125,51 @@ module Storage
|
|
125
125
|
|
126
126
|
def upload(path, local_file, options={})
|
127
127
|
local_file_name = File.basename(local_file)
|
128
|
-
bucket.
|
129
|
-
|
130
|
-
Pathname.new(local_file),
|
131
|
-
{ :content_type => derive_content_type(local_file_name) }.merge(options)
|
132
|
-
)
|
128
|
+
object = bucket.object(s3_path(path, local_file_name))
|
129
|
+
object.upload_file(Pathname.new(local_file), { :content_type => derive_content_type(local_file_name) }.merge(options))
|
133
130
|
end
|
134
131
|
|
135
132
|
def upload_dir(path, local_dir)
|
136
|
-
bucket.objects
|
133
|
+
bucket.objects(prefix: s3_path(path)).batch_delete!
|
137
134
|
Dir[File.join(local_dir, "*")].each do |f|
|
138
135
|
upload(path, f)
|
139
136
|
end
|
140
137
|
end
|
141
138
|
|
142
139
|
def content_type(path)
|
143
|
-
object(path).content_type
|
140
|
+
object(path).get.content_type
|
144
141
|
end
|
145
142
|
|
146
143
|
def copy(path, to_local_path)
|
147
|
-
|
148
|
-
raise "File(#{path}) does not exist in the bucket #{bucket.name}"
|
144
|
+
obj_content = read(path)
|
145
|
+
raise "File(#{path}) does not exist in the bucket #{bucket.name}" if obj_content.nil?
|
149
146
|
File.open(to_local_path, 'w') do |f|
|
150
|
-
|
151
|
-
f.write(c)
|
152
|
-
end
|
147
|
+
f.write(obj_content)
|
153
148
|
end
|
154
149
|
end
|
155
150
|
|
156
151
|
def write_to_file(path, content, options={})
|
157
|
-
object(path)
|
152
|
+
object = bucket.object(s3_path(path))
|
153
|
+
object.put({body: content}.merge(options))
|
158
154
|
end
|
159
155
|
|
160
156
|
def read(path)
|
161
|
-
object(path)
|
157
|
+
object = object(path)
|
158
|
+
return object.get.body.read unless object.nil?
|
159
|
+
object
|
162
160
|
end
|
163
161
|
|
164
162
|
def exists?(path)
|
165
|
-
object(path).
|
163
|
+
!object(path).nil?
|
166
164
|
end
|
167
165
|
|
168
|
-
def url_for(path, opts={})
|
166
|
+
def url_for(path, opts = {})
|
169
167
|
url_opts = {
|
170
|
-
|
171
|
-
|
168
|
+
:expires_in => opts.delete(:expires_in) || @url_expires,
|
169
|
+
:response_content_type => derive_content_type(path)
|
172
170
|
}.merge(opts)
|
173
|
-
object(path)
|
171
|
+
_object = object(path)
|
172
|
+
_object.nil? ? '' : _object.presigned_url(:get, url_opts)
|
174
173
|
end
|
175
174
|
|
176
175
|
def public_url(path, opts={})
|
@@ -183,19 +182,19 @@ module Storage
|
|
183
182
|
end
|
184
183
|
|
185
184
|
def delete(path)
|
186
|
-
bucket.objects
|
185
|
+
bucket.objects(prefix: s3_path(path)).batch_delete!
|
187
186
|
end
|
188
187
|
|
189
188
|
def clear
|
190
189
|
if s3_path.nil? || s3_path.empty?
|
191
190
|
bucket.clear
|
192
191
|
else
|
193
|
-
bucket.objects
|
192
|
+
bucket.objects(prefix: s3_path).batch_delete!
|
194
193
|
end
|
195
194
|
end
|
196
195
|
|
197
196
|
def objects(path)
|
198
|
-
bucket.objects
|
197
|
+
bucket.objects(prefix: s3_path(path))
|
199
198
|
end
|
200
199
|
|
201
200
|
private
|
@@ -205,11 +204,11 @@ module Storage
|
|
205
204
|
end
|
206
205
|
|
207
206
|
def s3
|
208
|
-
|
207
|
+
Aws::S3::Resource.new
|
209
208
|
end
|
210
209
|
|
211
210
|
def object(path)
|
212
|
-
bucket.objects
|
211
|
+
bucket.objects.find { |object| object.key == s3_path(path) }
|
213
212
|
end
|
214
213
|
|
215
214
|
def namespace
|
@@ -221,7 +220,7 @@ module Storage
|
|
221
220
|
end
|
222
221
|
|
223
222
|
def bucket
|
224
|
-
@bucket ||= s3.
|
223
|
+
@bucket ||= s3.bucket(bucket_name)
|
225
224
|
end
|
226
225
|
|
227
226
|
def bucket_name
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mingle-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ThoughtWorks Studios
|
@@ -13,15 +13,15 @@ dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- -
|
16
|
+
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '0'
|
19
|
-
name: aws-sdk-
|
19
|
+
name: aws-sdk-s3
|
20
20
|
prerelease: false
|
21
21
|
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: Mingle storage API to support filesystem and AWS S3 backed storage
|
@@ -43,17 +43,17 @@ require_paths:
|
|
43
43
|
- lib
|
44
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project:
|
56
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.6.13
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Mingle storage API to support filesystem and AWS S3 backed storage
|