Class: CarrierWave::Storage::Riak::File

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

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, bucket, key) ⇒ File

Returns a new instance of File.



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

def initialize(uploader, base, bucket, key)
  @uploader = uploader
  @bucket = bucket
  @key = key
  @base = base
end

Instance Method Details

#content_typeObject

Lookup value for file content-type header

Returns

String

value of content-type



88
89
90
# File 'lib/carrierwave/storage/riak.rb', line 88

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



99
100
101
# File 'lib/carrierwave/storage/riak.rb', line 99

def content_type=(new_content_type)
  @content_type = new_content_type
end

#deleteObject

Remove the file from Riak



139
140
141
142
143
144
145
146
147
# File 'lib/carrierwave/storage/riak.rb', line 139

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

#keyObject

Returns the key of the riak file

Returns

String

A filename



66
67
68
# File 'lib/carrierwave/storage/riak.rb', line 66

def key
  @key
end

#metaObject

Return riak meta data

Returns

Haash

A hash of X-Riak-Meta-* headers



110
111
112
# File 'lib/carrierwave/storage/riak.rb', line 110

def meta
  file.meta
end

#pathObject

Returns the path of the riak file

Returns

String

A full path to file



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

def path
  Pathname.new('/').join(@bucket).join(key).to_s
end

#readObject

Reads the contents of the file from Riak

Returns

String

contents of the file



132
133
134
# File 'lib/carrierwave/storage/riak.rb', line 132

def read
  file.raw_data
end

#sizeObject

Return size of file body

Returns

Integer

size of file body



121
122
123
# File 'lib/carrierwave/storage/riak.rb', line 121

def size
  file.raw_data.length
end

#store(file) ⇒ Object

Writes the supplied data into Riak

Returns

boolean



156
157
158
159
160
161
# File 'lib/carrierwave/storage/riak.rb', line 156

def store(file)
  @file = riak_client.store(@bucket, @key, file.read, {:content_type => file.content_type})
  @key = @file.key
  @uploader.key = @key
  true
end