Class: CarrierWave::Storage::UcloudFile

Inherits:
CarrierWave::SanitizedFile
  • Object
show all
Defined in:
lib/carrierwave/storage/ucloud_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ UcloudFile

Returns a new instance of UcloudFile.



6
7
8
9
10
11
# File 'lib/carrierwave/storage/ucloud_file.rb', line 6

def initialize(uploader, base, path)
  @uploader = uploader
  @path     = path
  @base     = base
  @bucket   = ::CarrierWave::Ucloud::Bucket.new(uploader)
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



4
5
6
# File 'lib/carrierwave/storage/ucloud_file.rb', line 4

def bucket
  @bucket
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/carrierwave/storage/ucloud_file.rb', line 4

def path
  @path
end

Instance Method Details

#content_typeObject



40
41
42
# File 'lib/carrierwave/storage/ucloud_file.rb', line 40

def content_type
  headers[:content_type]
end

#content_type=(new_content_type) ⇒ Object



44
45
46
# File 'lib/carrierwave/storage/ucloud_file.rb', line 44

def content_type=(new_content_type)
  headers[:content_type] = new_content_type
end

#deleteObject



28
29
30
# File 'lib/carrierwave/storage/ucloud_file.rb', line 28

def delete
  bucket.delete(path)
end

#exists?Boolean

Returns

Boolean

Whether the file exists

Returns:

  • (Boolean)


18
19
20
# File 'lib/carrierwave/storage/ucloud_file.rb', line 18

def exists?
  bucket.exists?(path)
end

#headersObject



48
49
50
# File 'lib/carrierwave/storage/ucloud_file.rb', line 48

def headers
  @headers ||= {}
end

#readObject



22
23
24
25
26
# File 'lib/carrierwave/storage/ucloud_file.rb', line 22

def read
  response = bucket.get(path)
  @headers = response.headers.deep_transform_keys { |k| k.underscore.to_sym rescue key }
  response.body
end

#store(file, headers = {}) ⇒ Object



36
37
38
# File 'lib/carrierwave/storage/ucloud_file.rb', line 36

def store(file, headers = {})
  bucket.put(path, file, headers)
end

#urlObject



32
33
34
# File 'lib/carrierwave/storage/ucloud_file.rb', line 32

def url
  bucket.url(path)
end