Class: Dragonfly::GoogleDataStore
- Inherits:
-
Object
- Object
- Dragonfly::GoogleDataStore
- Defined in:
- lib/dragonfly/google_data_store.rb,
lib/dragonfly/google_data_store/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#keyfile ⇒ Object
readonly
Returns the value of attribute keyfile.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy(uid) ⇒ Object
-
#initialize(opts) ⇒ GoogleDataStore
constructor
A new instance of GoogleDataStore.
- #read(uid) ⇒ Object
- #write(object, opts = {}) ⇒ Object
Constructor Details
#initialize(opts) ⇒ GoogleDataStore
Returns a new instance of GoogleDataStore.
9 10 11 12 13 |
# File 'lib/dragonfly/google_data_store.rb', line 9 def initialize(opts) @project = opts[:project] @keyfile = opts[:keyfile] @bucket_name = opts[:bucket] end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
7 8 9 |
# File 'lib/dragonfly/google_data_store.rb', line 7 def bucket_name @bucket_name end |
#keyfile ⇒ Object (readonly)
Returns the value of attribute keyfile.
7 8 9 |
# File 'lib/dragonfly/google_data_store.rb', line 7 def keyfile @keyfile end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
7 8 9 |
# File 'lib/dragonfly/google_data_store.rb', line 7 def project @project end |
Class Method Details
.generate_uid ⇒ Object
43 44 45 |
# File 'lib/dragonfly/google_data_store.rb', line 43 def self.generate_uid "#{Time.now.strftime('%Y/%m/%d/%H/%M')}/#{SecureRandom.uuid}" end |
Instance Method Details
#destroy(uid) ⇒ Object
37 38 39 40 41 |
# File 'lib/dragonfly/google_data_store.rb', line 37 def destroy(uid) bucket.file(uid).delete rescue nil end |
#read(uid) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dragonfly/google_data_store.rb', line 25 def read(uid) file = bucket.file uid content = file.download content.rewind [ content.read, file., ] rescue nil end |
#write(object, opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/dragonfly/google_data_store.rb', line 15 def write(object, opts = {}) ensure_bucket_exists uid = opts[:path] || Dragonfly::GoogleDataStore.generate_uid bucket.create_file object.tempfile.path, uid, metadata: object. uid end |