Module: Paperclip::Storage::Upyun
- Defined in:
- lib/paperclip/storage/upyun.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exists?(style_name = default_style) ⇒ Boolean
-
#flush_deletes ⇒ Object
:nodoc:.
-
#flush_writes ⇒ Object
:nodoc:.
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/upyun.rb', line 6 def self.extended base base.instance_eval do # Please use the latest paperclip from git://github.com/thoughtbot/paperclip.git # Since the latest one solves this issue: # https://github.com/thoughtbot/paperclip/issues/655 @upyun_bucketname = [:upyun_bucketname] || Paperclip::Storage::Upyun::Config[:upyun_bucketname] @upyun_username = [:upyun_username] || Paperclip::Storage::Upyun::Config[:upyun_username] @upyun_password = [:upyun_password] || Paperclip::Storage::Upyun::Config[:upyun_password] @upyun_domain = [:upyun_domain] || Paperclip::Storage::Upyun::Config[:upyun_domain] @upyun_api_host = [:upyun_api_host] || ( defined? Paperclip::Storage::Upyun::Config || Paperclip::Storage::Upyun::Config[:upyun_api_host].nil?) ? 'http://v1.api.upyun.com/' : Paperclip::Storage::Upyun::Config[:upyun_api_host] [:path] = [:path].gsub(/:url/, [:url]).gsub(/^:rails_root\/public/, @upyun_domain) [:url] = @upyun_domain + [:url] @resource = RestClient::Resource.new("#{@upyun_api_host}#{@upyun_bucketname}", :user => @upyun_username, :password => @upyun_password ) end end |
Instance Method Details
#exists?(style_name = default_style) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/paperclip/storage/upyun.rb', line 26 def exists?(style_name = default_style) if original_filename relative_path = path(style_name).gsub(@upyun_domain, '') begin true if @resource[relative_path].get.code == 200 rescue RestClient::ResourceNotFound false end else false end end |
#flush_deletes ⇒ Object
:nodoc:
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/paperclip/storage/upyun.rb', line 52 def flush_deletes #:nodoc: @queued_for_delete.each do |path| relative_path = path.gsub(@upyun_domain, '') begin @resource[relative_path].delete rescue end end @queued_for_delete = [] end |
#flush_writes ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/paperclip/storage/upyun.rb', line 40 def flush_writes #:nodoc: @queued_for_write.each do |style_name, file| current_path = '' relative_path = path(style_name).gsub(@upyun_domain, '') @resource[relative_path].post File.read(file), {'Expect' => '', 'Mkdir' => 'true'} end after_flush_writes # allows attachment to clean up temp files @queued_for_write = {} end |