module Paperclip::Storage::Riak

Public Class Methods

extended(base) click to toggle source
# File lib/paperclip-riak.rb, line 8
def self.extended(base)
  attr_accessor :riak_hosts, :riak_bucket, :riak_endpoint, :riak_client

  base.instance_eval do
    self.setup_options
  end
end

Public Instance Methods

bucket() click to toggle source
# File lib/paperclip-riak.rb, line 28
def bucket
  @bucket ||= riak.bucket(@riak_bucket)
end
copy_to_local_file(style, local_dest_path) click to toggle source
# File lib/paperclip-riak.rb, line 66
def copy_to_local_file(style, local_dest_path)
  ::File.open(local_dest_path, 'wb') do |local_file|
    file = bucket.get(path(style))
    local_file.write(file.raw_data)
  end
end
exists?(style = default_style) click to toggle source
# File lib/paperclip-riak.rb, line 41
def exists?(style = default_style)
  if original_filename
    bucket.exists?(path(style))
  else
    false
  end
end
flush_deletes() click to toggle source
# File lib/paperclip-riak.rb, line 59
def flush_deletes
  @queued_for_delete.each do |path|
    bucket.delete path
  end
  @queued_for_delete = []
end
flush_writes() click to toggle source
# File lib/paperclip-riak.rb, line 49
def flush_writes
  @queued_for_write.each do |style, file|
    object = ::Riak::RObject.new(bucket, path(style))
    object.raw_data = File.read(file.path)
    object.content_type = file.content_type.to_s.strip
    object.store
  end
  @queued_for_write = {}
end
riak() click to toggle source
# File lib/paperclip-riak.rb, line 24
def riak
  @riak ||= @riak_client || ::Riak::Client.new(@client_options)
end
setup_options() click to toggle source
# File lib/paperclip-riak.rb, line 32
def setup_options
  @client_options = {
    :nodes => @options[:riak_hosts]
  }
  @riak_bucket = @options[:riak_bucket]
  @riak_endpoint = @options[:riak_endpoint]
  @riak_client = @options[:riak_client]
end
url(style=default_style, options={}) click to toggle source
# File lib/paperclip-riak.rb, line 16
def url(style=default_style, options={})
  if @riak_endpoint
    "#{@riak_endpoint}/#{@riak_bucket}/#{path(style)}"
  else
    @url_generator.for(style, options)
  end
end