dragonfly-google_data_store 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/dragonfly/google_data_store.rb +23 -10
- data/lib/dragonfly/google_data_store/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d75919d7b7789fc892325542559247c88865573b
|
4
|
+
data.tar.gz: 4b3739a31a44f24982d76b127e62b373d8c706ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fb64ee97bd38e947c0e29894972abc4bb3aa9710809b94301199992bb213949d0c20c71f3bdbbc7e09c84995531daf7e8e50a4bda01898ad984537f7ce9cbec
|
7
|
+
data.tar.gz: 583f9fba8873961a29db743630e6b09a4067ac22b1f2e5682ede5981054bd13351fad955e3bf5bf7bd2ae766d50f4e7bc4c5cdb4764b6c4b3c0f928d18e713d8
|
data/README.md
CHANGED
@@ -32,7 +32,8 @@ Dragonfly.app.configure do
|
|
32
32
|
datastore :google,
|
33
33
|
project: 'project-id-here',
|
34
34
|
bucket: 'bucket-name-here',
|
35
|
-
keyfile: 'path/to/your/key/file.json'
|
35
|
+
keyfile: 'path/to/your/key/file.json',
|
36
|
+
root_path: 'root/path'
|
36
37
|
end
|
37
38
|
```
|
38
39
|
|
@@ -50,4 +51,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
50
51
|
## License
|
51
52
|
|
52
53
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
-
|
@@ -4,12 +4,13 @@ require 'google/cloud/storage'
|
|
4
4
|
|
5
5
|
module Dragonfly
|
6
6
|
class GoogleDataStore
|
7
|
-
attr_reader :project, :keyfile, :bucket_name
|
7
|
+
attr_reader :project, :keyfile, :bucket_name, :root_path
|
8
8
|
|
9
9
|
def initialize(opts)
|
10
10
|
@project = opts[:project]
|
11
11
|
@keyfile = opts[:keyfile]
|
12
12
|
@bucket_name = opts[:bucket]
|
13
|
+
@root_path = opts[:root_path]
|
13
14
|
end
|
14
15
|
|
15
16
|
def write(object, opts = {})
|
@@ -17,26 +18,34 @@ module Dragonfly
|
|
17
18
|
|
18
19
|
uid = opts[:path] || Dragonfly::GoogleDataStore.generate_uid
|
19
20
|
|
20
|
-
bucket.create_file
|
21
|
+
bucket.create_file(
|
22
|
+
object.tempfile.path,
|
23
|
+
full_path(uid),
|
24
|
+
metadata: object.meta,
|
25
|
+
content_type: object.mime_type
|
26
|
+
)
|
21
27
|
|
22
28
|
uid
|
23
29
|
end
|
24
30
|
|
25
31
|
def read(uid)
|
26
|
-
file = bucket.file uid
|
32
|
+
file = bucket.file full_path(uid)
|
33
|
+
|
34
|
+
metadata = file.metadata.dup
|
35
|
+
metadata['name'] ||= File.basename(file.name)
|
36
|
+
|
27
37
|
content = file.download
|
28
38
|
content.rewind
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
]
|
33
|
-
rescue
|
39
|
+
|
40
|
+
[content.read, metadata]
|
41
|
+
rescue StandardError
|
34
42
|
nil
|
35
43
|
end
|
36
44
|
|
37
45
|
def destroy(uid)
|
38
|
-
bucket.file(uid)
|
39
|
-
|
46
|
+
file = bucket.file full_path(uid)
|
47
|
+
file.delete
|
48
|
+
rescue StandardError
|
40
49
|
nil
|
41
50
|
end
|
42
51
|
|
@@ -46,6 +55,10 @@ module Dragonfly
|
|
46
55
|
|
47
56
|
private
|
48
57
|
|
58
|
+
def full_path(uid)
|
59
|
+
File.join *[root_path, uid].compact
|
60
|
+
end
|
61
|
+
|
49
62
|
def bucket
|
50
63
|
@bucket ||= storage.bucket(bucket_name)
|
51
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dragonfly-google_data_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raffael Schmid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dragonfly
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.5.2
|
107
|
+
rubygems_version: 2.5.2.3
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: A data store for dragonfly using google cloud
|