Class: CarrierWave::Storage::TT::File

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

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ File

Returns a new instance of File.



52
53
54
55
56
# File 'lib/carrierwave/storage/tt.rb', line 52

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

Instance Method Details

#content_typeObject



111
112
113
# File 'lib/carrierwave/storage/tt.rb', line 111

def content_type
  headers[:content_type]
end

#content_type=(new_content_type) ⇒ Object



115
116
117
# File 'lib/carrierwave/storage/tt.rb', line 115

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

#deleteObject

Remove the file from Cloud Files



85
86
87
88
89
90
91
92
93
# File 'lib/carrierwave/storage/tt.rb', line 85

def delete
  begin
    tt_connection.delete(@path)
    true
  rescue Exception => e
    # If the file's not there, don't panic
    nil
  end
end

#pathObject

Returns the current path/filename of the file on Cloud Files.

Returns

String

A path



65
66
67
# File 'lib/carrierwave/storage/tt.rb', line 65

def path
  @path
end

#readObject

Reads the contents of the file from Cloud Files

Returns

String

contents of the file



76
77
78
79
80
# File 'lib/carrierwave/storage/tt.rb', line 76

def read
  object = tt_connection.get(@path)
  @headers = object.headers
  object.net_http_res.body
end

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

Writes the supplied data into the object on Cloud Files.

Returns

boolean



126
127
128
129
# File 'lib/carrierwave/storage/tt.rb', line 126

def store(data,headers={})
  tt_connection.put(@path, data, {'Expect' => '', 'Mkdir' => 'true'}.merge(headers))
  true
end

#urlObject

Returns the url on the Cloud Files CDN. Note that the parent container must be marked as public for this to work.

Returns

String

file’s url



103
104
105
106
107
108
109
# File 'lib/carrierwave/storage/tt.rb', line 103

def url
  if @uploader.tt_domain
    "http://" + @uploader.tt_domain + '/' + @path
  else
    "#{@uploader.tt_host}:#{@uploader.tt_port}/#{@path}"
  end
end