Module: Paperclip::Storage::Qin
- Defined in:
- lib/paperclip/storage/qin.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
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/paperclip/storage/qin.rb', line 4 def self.extended base begin require 'qiniu' rescue LoadError => e e. << " (You may need to install the qiniu gem)#{Qiniu}" raise e end 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
24 25 26 27 |
# File 'lib/paperclip/storage/qin.rb', line 24 def exists?(style = default_style) init !!Qiniu::Storage.stat(bucket,path(style)) end |
#flush_deletes ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/paperclip/storage/qin.rb', line 46 def flush_deletes init for path in @queued_for_delete do Qiniu::Storage.delete(bucket, path) end @queued_for_delete = [] end |
#flush_writes ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/paperclip/storage/qin.rb', line 29 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
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/paperclip/storage/qin.rb', line 54 def public_url(style = default_style) init if @options[:qiniu_host] "#{@public_url}" else code, result, response_headers = Qiniu::Storage.stat(bucket, path(style)) if code==200 "http://orh1veryp.bkt.clouddn.com/#{path(style)}" else nil end end end |