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.1.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.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
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 14 |
# File 'lib/dragonfly/google_data_store.rb', line 9 def initialize(opts) @project = opts[:project] @keyfile = opts[:keyfile] @bucket_name = opts[:bucket] @root_path = opts[:root_path] 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 |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
7 8 9 |
# File 'lib/dragonfly/google_data_store.rb', line 7 def root_path @root_path end |
Class Method Details
.generate_uid ⇒ Object
52 53 54 |
# File 'lib/dragonfly/google_data_store.rb', line 52 def self.generate_uid "#{Time.now.strftime('%Y/%m/%d/%H/%M')}/#{SecureRandom.uuid}" end |
Instance Method Details
#destroy(uid) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/dragonfly/google_data_store.rb', line 45 def destroy(uid) file = bucket.file full_path(uid) file.delete rescue StandardError nil end |
#read(uid) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dragonfly/google_data_store.rb', line 31 def read(uid) file = bucket.file full_path(uid) = file..dup ['name'] ||= File.basename(file.name) content = file.download content.rewind [content.read, ] rescue StandardError nil end |
#write(object, opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dragonfly/google_data_store.rb', line 16 def write(object, opts = {}) ensure_bucket_exists uid = opts[:path] || Dragonfly::GoogleDataStore.generate_uid bucket.create_file( object.tempfile.path, full_path(uid), metadata: object., content_type: object.mime_type ) uid end |