Class: Persistable::CloudStorageAdapter
- Inherits:
-
Object
- Object
- Persistable::CloudStorageAdapter
- Defined in:
- lib/persistable/cloud_storage_adapter.rb
Overview
CloudStorageAdapter powered by the fog gem
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options used during the object initialization.
Instance Method Summary collapse
-
#delete(persistable) ⇒ @see #write
Deletes file named ‘persistable#persistance_key` from storage.
-
#initialize(options = {}) ⇒ CloudStorageAdapter
constructor
Creates a new ‘CloudStorageAdapter`.
-
#read(persistable) ⇒ @see #write
Reads the data on the cloud and write it on the ‘persistance_data` property of `persistable` object.
-
#write(persistable) ⇒ Boolean
Write the data given by ‘#persisence_data` method to the cloud.
Constructor Details
#initialize(options = {}) ⇒ CloudStorageAdapter
Creates a new ‘CloudStorageAdapter`
22 23 24 25 26 27 28 29 |
# File 'lib/persistable/cloud_storage_adapter.rb', line 22 def initialize( = {}) @options = available_providers = Fog::Storage.providers available_providers.include?(provider) or raise ArgumentError, "Unknown Fog::Storage provider. Should be on of \ #{available_providers.inspect}, given provider" directory_name or raise ArgumentError, "Directory to save file should be given." check_connection end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns Options used during the object initialization.
11 12 13 |
# File 'lib/persistable/cloud_storage_adapter.rb', line 11 def @options end |
Instance Method Details
#delete(persistable) ⇒ @see #write
Deletes file named ‘persistable#persistance_key` from storage
58 59 60 61 62 63 |
# File 'lib/persistable/cloud_storage_adapter.rb', line 58 def delete(persistable) if file = directory.files.head(persistable.persistence_key) return file.destroy end false end |
#read(persistable) ⇒ @see #write
Reads the data on the cloud and write it on the ‘persistance_data` property of `persistable` object
46 47 48 49 50 51 52 |
# File 'lib/persistable/cloud_storage_adapter.rb', line 46 def read(persistable) if file = directory.files.get(persistable.persistence_key) persistable.persistence_data = StringIO.new(file.body) return true end false end |
#write(persistable) ⇒ Boolean
Write the data given by ‘#persisence_data` method to the cloud
35 36 37 38 39 40 |
# File 'lib/persistable/cloud_storage_adapter.rb', line 35 def write(persistable) if persistable.persistence_data return directory.files.create(:key => persistable.persistence_key, :body => persistable.persistence_data) end return false end |