Class: CarrierWave::Storage::Sharefile::File

Inherits:
Object
  • Object
show all
Includes:
Utilities::Uri
Defined in:
lib/carrierwave/storage/sharefile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, config, path, client) ⇒ File

Returns a new instance of File.



45
46
47
# File 'lib/carrierwave/storage/sharefile.rb', line 45

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



43
44
45
# File 'lib/carrierwave/storage/sharefile.rb', line 43

def path
  @path
end

Instance Method Details

#content_typeObject

Lookup value for file content-type header

Returns

String

value of content-type



71
72
73
# File 'lib/carrierwave/storage/sharefile.rb', line 71

def content_type
  @content_type || file.content_type
end

#content_type=(new_content_type) ⇒ Object

Set non-default content-type header (default is file.content_type)

Returns

String

returns new content type value



82
83
84
# File 'lib/carrierwave/storage/sharefile.rb', line 82

def content_type=(new_content_type)
  @content_type = new_content_type
end

#deleteObject

Removes a file from the service

Returns

Boolean

true on success or raises error



118
119
120
# File 'lib/carrierwave/storage/sharefile.rb', line 118

def delete
  @client.delete_document(@path)
end

#filenameObject



49
50
51
# File 'lib/carrierwave/storage/sharefile.rb', line 49

def filename
  Pathname.new(path).basename.to_s
end

#readObject

Read content of file from service

Returns

String

contents of file



92
93
94
# File 'lib/carrierwave/storage/sharefile.rb', line 92

def read
  file
end

#retrieve(identifier) ⇒ Object

Retrieve file from service

Returns

File


143
144
145
146
# File 'lib/carrierwave/storage/sharefile.rb', line 143

def retrieve(identifier)
  @file = @client.get_document(identifier)
  @file ||= @file.parsed_response
end

#sharefile_attributesObject



107
108
109
# File 'lib/carrierwave/storage/sharefile.rb', line 107

def sharefile_attributes
  attributes
end

#sizeObject

Return size of file body

Returns

Integer

size of file body



103
104
105
# File 'lib/carrierwave/storage/sharefile.rb', line 103

def size
  file.content_length
end

#store(file) ⇒ Object

Write file to service

Returns

Boolean

true on success or raises error



129
130
131
132
133
134
# File 'lib/carrierwave/storage/sharefile.rb', line 129

def store(file)
  sharefile_file = file.to_file
  @content_type ||= file.content_type
  root_folder = @config[:sharefile_root]
  @file = @client.store_document(root_folder, @path, sharefile_file)
end

#urlObject

Lookup URL for the path

Returns

String

URL of the download link



60
61
62
# File 'lib/carrierwave/storage/sharefile.rb', line 60

def url
  @client.get_download_link(@path)
end