Class: Attached::Storage::Fog
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
Instance Method Summary collapse
-
#destroy(path) ⇒ Object
Destroy a file at a given path.
-
#host ⇒ Object
Access the host for a storage service (must override).
-
#initialize(credentials) ⇒ Fog
constructor
Create a new interface supporting save and destroy operations (should be overridden and called).
-
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
-
#save(file, path) ⇒ Object
Save a file to a given path.
Methods inherited from Base
Constructor Details
#initialize(credentials) ⇒ Fog
Create a new interface supporting save and destroy operations (should be overridden and called).
11 12 13 |
# File 'lib/attached/storage/fog.rb', line 11 def initialize(credentials) @defaults = { public: true, metadata: Attached::Attachment.[:metadata] } end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
8 9 10 |
# File 'lib/attached/storage/fog.rb', line 8 def defaults @defaults end |
Instance Method Details
#destroy(path) ⇒ Object
Destroy a file at a given path.
Parameters:
-
path - The path to destroy.
58 59 60 |
# File 'lib/attached/storage/fog.rb', line 58 def destroy(path) directory.files.get(path).destroy if directory.files.head(path) end |
#host ⇒ Object
Access the host for a storage service (must override).
Usage:
storage.host
20 21 22 |
# File 'lib/attached/storage/fog.rb', line 20 def host() raise NotImplementedError.new end |
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
Parameters:
-
path - The path to retrieve.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/attached/storage/fog.rb', line 41 def retrieve(path) file = directory.files.get(path) body = file.body extname = File.extname(path) basename = File.basename(path, extname) file = Tempfile.new([basename, extname]) file.binmode file.write(body) file.rewind file end |
#save(file, path) ⇒ Object
Save a file to a given path.
Parameters:
-
file - The file to save.
-
path - The path to save.
30 31 32 33 34 |
# File 'lib/attached/storage/fog.rb', line 30 def save(file, path) file = File.open(file.path) directory.files.create(self.(path).merge(self.defaults.merge(key: path, body: file))) file.close end |