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



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

def content_type
  headers[:content_type]
end

#content_type=(new_content_type) ⇒ Object



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

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

#deleteObject



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

def delete
  bucket.delete(path)
end

#headersObject



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

def headers
  @headers ||= {}
end

#readObject



13
14
15
16
17
# File 'lib/carrierwave/storage/ucloud_file.rb', line 13

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



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

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

#url(opts = {}) ⇒ Object



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

def url(opts = {})
  bucket.url(path, opts)
end