Class: CarrierWave::Storage::Roz::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/roz.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, path) ⇒ File

Returns a new instance of File.



29
30
31
32
# File 'lib/carrierwave/storage/roz.rb', line 29

def initialize(uploader, path)
  @uploader = uploader
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



25
26
27
# File 'lib/carrierwave/storage/roz.rb', line 25

def path
  @path
end

#uploaderObject (readonly)

Returns the value of attribute uploader.



26
27
28
# File 'lib/carrierwave/storage/roz.rb', line 26

def uploader
  @uploader
end

Instance Method Details

#content_typeObject



73
74
75
# File 'lib/carrierwave/storage/roz.rb', line 73

def content_type
  file.content_type
end

#deleteObject



63
64
65
66
67
68
69
70
71
# File 'lib/carrierwave/storage/roz.rb', line 63

def delete
  response = client.delete(path)

  unless (200..208).include? response.code.to_i
    # json = JSON.parse(response.to_str)
    # TODO: try to parse and raise JSON error message
    raise response.to_s
  end
end

#filenameObject



55
56
57
# File 'lib/carrierwave/storage/roz.rb', line 55

def filename
  ::File.basename(path)
end

#lengthObject Also known as: content_length, file_length, size



77
78
79
# File 'lib/carrierwave/storage/roz.rb', line 77

def length
  file.length
end

#readObject



59
60
61
# File 'lib/carrierwave/storage/roz.rb', line 59

def read
  file.content
end

#store(file) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/carrierwave/storage/roz.rb', line 34

def store(file)
  response = client.upload(file, path)

  unless (200..208).include? response.code.to_i
    # json = JSON.parse(response.to_str)
    # TODO: try to parse and raise JSON error message
    raise response.to_s
  end
end

#url(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/carrierwave/storage/roz.rb', line 44

def url(*args)
  if path == ::File.basename(path)
    # Backwards compatibility for when we were storing only the filename
    URI.join(uploader.files_base_url, "#{uploader.access_id.to_s}/", "#{uploader.store_dir}/", path).to_s
  else
    dirname = ::File.dirname(path)
    basename = [uploader.version_name, ::File.basename(path)].compact.join('_')
    URI.join(uploader.files_base_url, "#{dirname}/", basename).to_s
  end
end