Module: Paperclip::Storage::TokyoTyrant
- Defined in:
- lib/tokyo_tyrant.rb,
lib/paperclip/storage/tokyo_tyrant.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_to_local_file(style, local_dest_path) ⇒ Object
- #exists?(style_name = default_style) ⇒ Boolean
-
#flush_deletes ⇒ Object
:nodoc:.
-
#flush_writes ⇒ Object
:nodoc:.
- #tt_bucket ⇒ Object
- #tt_object(style_name = default_style) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/tokyo_tyrant.rb', line 4 def self.extended base begin require 'rufus/tokyo/tyrant' rescue LoadError => e e. << " (You may need to install the rufus-tokyo gem)" raise e end end |
Instance Method Details
#copy_to_local_file(style, local_dest_path) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/tokyo_tyrant.rb', line 51 def copy_to_local_file(style, local_dest_path) log("copying #{path(style)} to local file #{local_dest_path}") local_file = ::File.open(local_dest_path, 'wb') tt_bucket[path(style).sub(%r{^/},'')] = local_file.read rescue warn("cannot copy #{path(style)} to local file #{local_dest_path}") false end |
#exists?(style_name = default_style) ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/tokyo_tyrant.rb', line 13 def exists?(style_name = default_style) if original_filename tt_object(style_name) else false end end |
#flush_deletes ⇒ Object
:nodoc:
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tokyo_tyrant.rb', line 39 def flush_deletes #:nodoc: @queued_for_delete.each do |path| begin log("deleting #{path}") tt_bucket.delete(path) rescue Errno::ENOENT => e # ignore file-not-found, let everything else pass end end @queued_for_delete = [] end |
#flush_writes ⇒ Object
:nodoc:
29 30 31 32 33 34 35 36 37 |
# File 'lib/tokyo_tyrant.rb', line 29 def flush_writes #:nodoc: @queued_for_write.each do |style_name, file| tt_bucket[path(style_name).sub(%r{^/},'')] = file.read end after_flush_writes # allows attachment to clean up temp files @queued_for_write = {} end |
#tt_bucket ⇒ Object
21 22 23 |
# File 'lib/tokyo_tyrant.rb', line 21 def tt_bucket @tt_bucket ||= Rufus::Tokyo::Tyrant.new(@options[:tt_host], @options[:tt_port]) end |
#tt_object(style_name = default_style) ⇒ Object
25 26 27 |
# File 'lib/tokyo_tyrant.rb', line 25 def tt_object style_name = default_style tt_bucket[path(style_name).sub(%r{^/},'')] end |