Module: Paperclip::Storage::Riak
- Defined in:
- lib/paperclip-riak.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bucket ⇒ Object
- #copy_to_local_file(style, local_dest_path) ⇒ Object
- #exists?(style = default_style) ⇒ Boolean
- #flush_deletes ⇒ Object
- #flush_writes ⇒ Object
- #riak ⇒ Object
- #setup_options ⇒ Object
- #url(style = default_style, options = {}) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
8 9 10 11 12 13 14 |
# 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. end end |
Instance Method Details
#bucket ⇒ Object
28 29 30 |
# File 'lib/paperclip-riak.rb', line 28 def bucket @bucket ||= riak.bucket(@riak_bucket) end |
#copy_to_local_file(style, local_dest_path) ⇒ Object
66 67 68 69 70 71 |
# 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) ⇒ Boolean
41 42 43 44 45 46 47 |
# 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 ⇒ Object
59 60 61 62 63 64 |
# 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 ⇒ Object
49 50 51 52 53 54 55 56 57 |
# 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 ⇒ Object
24 25 26 |
# File 'lib/paperclip-riak.rb', line 24 def riak @riak ||= @riak_client || ::Riak::Client.new(@client_options) end |
#setup_options ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/paperclip-riak.rb', line 32 def @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 = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/paperclip-riak.rb', line 16 def url(style=default_style, ={}) if @riak_endpoint "#{@riak_endpoint}/#{@riak_bucket}/#{path(style)}" else @url_generator.for(style, ) end end |