Class: CarrierWave::Storage::GoogleDrive::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::GoogleDrive::File
- Defined in:
- lib/carrierwave/storage/google_drive.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #content_type ⇒ Object
- #delete ⇒ Object
- #extension ⇒ Object
-
#initialize(uploader, storage, resource_id = nil) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #store(file) ⇒ Object
- #url(options = { }) ⇒ Object
Constructor Details
#initialize(uploader, storage, resource_id = nil) ⇒ File
Returns a new instance of File.
26 27 28 29 30 31 |
# File 'lib/carrierwave/storage/google_drive.rb', line 26 def initialize(uploader, storage, resource_id = nil) @uploader = uploader @storage = storage @version_name = (uploader.version_name||'default').to_sym @resource_id = YAML.load(resource_id.to_s)[@version_name] rescue "" end |
Instance Method Details
#connection ⇒ Object
47 48 49 |
# File 'lib/carrierwave/storage/google_drive.rb', line 47 def connection @storage.connection end |
#content_type ⇒ Object
51 52 53 54 |
# File 'lib/carrierwave/storage/google_drive.rb', line 51 def content_type @content_type ||= file.available_content_types.first @content_type end |
#delete ⇒ Object
41 42 43 44 45 |
# File 'lib/carrierwave/storage/google_drive.rb', line 41 def delete if @resource_id.present? file.delete end end |
#extension ⇒ Object
55 56 57 |
# File 'lib/carrierwave/storage/google_drive.rb', line 55 def extension content_type.to_s end |
#read ⇒ Object
63 64 65 |
# File 'lib/carrierwave/storage/google_drive.rb', line 63 def read open(url).read end |
#store(file) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/carrierwave/storage/google_drive.rb', line 33 def store(file) @remote_file = connection.upload_from_file(file.path, nil, :convert => false) @remote_file.acl.push( {:scope_type => "default", :role => "reader"}) @resource_id = @remote_file.resource_id.split(':').last @uploader.key = @remote_file.resource_id.split(':').last @resource_id end |
#url(options = { }) ⇒ Object
59 60 61 |
# File 'lib/carrierwave/storage/google_drive.rb', line 59 def url( = { }) "https://docs.google.com/uc?&id=#{@resource_id}" end |