upyun-paperclip 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,9 +6,18 @@ This gem allows you to use [UpYun Storage](http://www.upyun.com) as storage engi
6
6
 
7
7
  gem install upyun-paperclip
8
8
 
9
+ ## Rails 3
10
+
11
+ Using paperclip's master branch since this [issue](https://github.com/thoughtbot/paperclip/issues/655) is fixed in it.
12
+
13
+ gem "paperclip", :git => 'git://github.com/thoughtbot/paperclip.git'
14
+ gem "upyun-paperclip", :git => 'git://github.com/frankel/upyun-paperclip.git'
15
+
9
16
  ## Usage
10
17
 
11
- For example, if you have a model named User, then you can
18
+ If you have a model named User, then you can set options like this.
19
+
20
+ ### One model
12
21
 
13
22
  ```ruby
14
23
  class User < ActiveRecord::Base
@@ -27,4 +36,17 @@ class User < ActiveRecord::Base
27
36
  }
28
37
  end
29
38
  ```
39
+ ### Multiple models
40
+
41
+ If you have more than one model to use paperclip, and feel bored to set the same options for each one, you can create a file named `paperclip.rb` under `config\initializers` folder, and write code like this:
42
+
43
+ ```ruby
44
+ Paperclip::Storage::Upyun::Config = {
45
+ :upyun_bucketname => 'bucketname',
46
+ :upyun_username => 'username',
47
+ :upyun_password => 'password',
48
+ :upyun_domain => 'domain'
49
+ }
50
+ ```
30
51
 
52
+ and only set `:storage => :upyun` in each models.
@@ -1,16 +1,24 @@
1
+ require 'rest-client'
2
+
1
3
  module Paperclip
2
4
  module Storage
3
5
  module Upyun
4
6
  def self.extended base
5
7
  base.instance_eval do
6
- @upyun_bucketname = @options[:upyun_bucketname]
7
- @upyun_username = @options[:upyun_username]
8
- @upyun_password = @options[:upyun_password]
9
- @upyun_domain = @options[:upyun_domain]
10
- @upyun_api_host = @options[:upyun_api_host] || 'http://v1.api.upyun.com/'
11
8
 
12
- @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public\/system/, @upyun_domain)
9
+ # Please use the latest paperclip from git://github.com/thoughtbot/paperclip.git
10
+ # Since the latest one solves this issue:
11
+ # https://github.com/thoughtbot/paperclip/issues/655
12
+
13
+ @upyun_bucketname = @options[:upyun_bucketname] || Paperclip::Storage::Upyun::Config[:upyun_bucketname]
14
+ @upyun_username = @options[:upyun_username] || Paperclip::Storage::Upyun::Config[:upyun_username]
15
+ @upyun_password = @options[:upyun_password] || Paperclip::Storage::Upyun::Config[:upyun_password]
16
+ @upyun_domain = @options[:upyun_domain] || Paperclip::Storage::Upyun::Config[:upyun_domain]
17
+ @upyun_api_host = @options[:upyun_api_host] || Paperclip::Storage::Upyun::Config[:upyun_api_host] || 'http://v1.api.upyun.com/'
13
18
 
19
+ @options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/^:rails_root\/public/, @upyun_domain)
20
+ @options[:url] = @upyun_domain + @options[:url]
21
+
14
22
  @resource = RestClient::Resource.new("#{@upyun_api_host}#{@upyun_bucketname}", :user => @upyun_username, :password => @upyun_password )
15
23
  end
16
24
  end
@@ -30,7 +38,7 @@ module Paperclip
30
38
 
31
39
 
32
40
  def flush_writes #:nodoc:
33
- @queued_for_write.each do |style_name, file|
41
+ @queued_for_write.each do |style_name, file|
34
42
  current_path = ''
35
43
  relative_path = path(style_name).gsub(@upyun_domain, '')
36
44
  path_array = relative_path.split('/')
@@ -51,7 +59,11 @@ module Paperclip
51
59
 
52
60
  def flush_deletes #:nodoc:
53
61
  @queued_for_delete.each do |path|
54
- # TODO:
62
+ relative_path = path.gsub(@upyun_domain, '')
63
+ begin
64
+ @resource[relative_path].delete
65
+ rescue
66
+ end
55
67
  end
56
68
  @queued_for_delete = []
57
69
  end
@@ -1,5 +1,5 @@
1
1
  module Upyun
2
2
  module Paperclip
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - frankel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-01-05 00:00:00 +08:00
17
+ date: 2012-01-06 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency