Class: Attached::Storage::Fog
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
readonly
Returns the value of attribute access_key_id.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#secret_access_key ⇒ Object
readonly
Returns the value of attribute secret_access_key.
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).
19 20 21 |
# File 'lib/attached/storage/fog.rb', line 19 def initialize(credentials) @defaults = { :public => true, :metadata => Attached::Attachment.[:metadata] } end |
Instance Attribute Details
#access_key_id ⇒ Object (readonly)
Returns the value of attribute access_key_id.
13 14 15 |
# File 'lib/attached/storage/fog.rb', line 13 def access_key_id @access_key_id end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/attached/storage/fog.rb', line 12 def bucket @bucket end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
10 11 12 |
# File 'lib/attached/storage/fog.rb', line 10 def defaults @defaults end |
#secret_access_key ⇒ Object (readonly)
Returns the value of attribute secret_access_key.
14 15 16 |
# File 'lib/attached/storage/fog.rb', line 14 def secret_access_key @secret_access_key end |
Instance Method Details
#destroy(path) ⇒ Object
Destroy a file at a given path.
Parameters:
-
path - The path to destroy.
78 79 80 |
# File 'lib/attached/storage/fog.rb', line 78 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
30 31 32 |
# File 'lib/attached/storage/fog.rb', line 30 def host() raise NotImplementedError.new end |
#retrieve(path) ⇒ Object
Retrieve a file from a given path.
Parameters:
-
path - The path to retrieve.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/attached/storage/fog.rb', line 55 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.
42 43 44 45 46 |
# File 'lib/attached/storage/fog.rb', line 42 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 |