Class: CarrierWave::Storage::Grandcloud::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Grandcloud::File
- Defined in:
- lib/carrierwave/storage/grandcloud.rb
Instance Method Summary collapse
-
#delete ⇒ Object
Remove the file from Cloud Files.
-
#initialize(uploader, base, path) ⇒ File
constructor
A new instance of File.
-
#path ⇒ Object
Returns the current path/filename of the file on Cloud Files.
-
#read ⇒ Object
Reads the contents of the file from Cloud Files.
- #store(data) ⇒ Object
- #url(expires_at = Time.now + 3000) ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
11 12 13 14 15 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 11 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Method Details
#delete ⇒ Object
Remove the file from Cloud Files
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 43 def delete begin object = bucket.objects.find(@path) object.destroy true rescue Exception => e # If the file's not there, don't panic nil end end |
#path ⇒ Object
Returns the current path/filename of the file on Cloud Files.
Returns
- String
-
A path
24 25 26 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 24 def path @path end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
35 36 37 38 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 35 def read object = bucket.objects.find(@path) object.content end |
#store(data) ⇒ Object
67 68 69 70 71 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 67 def store(data) new_object = bucket.objects.build(@path) new_object.content = data new_object.save end |
#url(expires_at = Time.now + 3000) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/carrierwave/storage/grandcloud.rb', line 54 def url(expires_at = Time.now + 3000) unless @uploader.grandcloud_bucket_private "http://#{Sndacs::REGION_CONTENT_HOST % @uploader.grandcloud_location}/#{@uploader.grandcloud_bucket}/#{path}" else object = bucket.objects.find(@path) if bucket.policy == "Allow" object.url else object.temporary_url(expires_at) end end end |