Module: Paperclip::Storage::Qiniu
- Defined in:
- lib/paperclip/storage/qiniu.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exists?(style = default_style) ⇒ Boolean
- #flush_deletes ⇒ Object
- #flush_writes ⇒ Object
- #public_url(style = default_style) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/paperclip/storage/qiniu.rb', line 6 def self.extended base begin require 'qiniu-rs' rescue LoadError => e e. << " (You may need to install the qiniu-rs gem)" raise e end unless defined?(::Qiniu) base.instance_eval do unless @options[:url].to_s.match(/^:fog.*url$/) @options[:path] = @options[:path].gsub(/:url/, @options[:url]) @options[:url] = ':qiniu_public_url' end Paperclip.interpolates(:qiniu_public_url) do |, style| .public_url(style) end unless Paperclip::Interpolations.respond_to? :qiniu_public_url end end |
Instance Method Details
#exists?(style = default_style) ⇒ Boolean
26 27 28 29 |
# File 'lib/paperclip/storage/qiniu.rb', line 26 def exists?(style = default_style) init !!::Qiniu::RS.stat(bucket, path(style)) end |
#flush_deletes ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/paperclip/storage/qiniu.rb', line 48 def flush_deletes init for path in @queued_for_delete do ::Qiniu::RS.delete(bucket, path) end @queued_for_delete = [] end |
#flush_writes ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/paperclip/storage/qiniu.rb', line 31 def flush_writes init for style, file in @queued_for_write do log("saving #{path(style)}") retried = false begin upload(file, path(style)) ensure file.rewind end end after_flush_writes # allows attachment to clean up temp files @queued_for_write = {} end |
#public_url(style = default_style) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/paperclip/storage/qiniu.rb', line 56 def public_url(style = default_style) init if @options[:qiniu_host] "#{dynamic_fog_host_for_style(style)}/#{path(style)}" else res = ::Qiniu::RS.get(bucket, path(style)) if res res["url"] else nil end end end |