paperclip-qiniu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paperclip-qiniu (0.0.1)
4
+ paperclip-qiniu (0.0.2)
5
5
  paperclip
6
6
  qiniu-rs
7
7
 
@@ -22,11 +22,12 @@ GEM
22
22
  arel (3.0.2)
23
23
  builder (3.0.0)
24
24
  cocaine (0.2.1)
25
+ diff-lcs (1.1.3)
25
26
  i18n (0.6.0)
26
27
  json (1.7.3)
27
28
  mime-types (1.19)
28
29
  multi_json (1.3.6)
29
- paperclip (3.1.2)
30
+ paperclip (3.1.3)
30
31
  activemodel (>= 3.0.0)
31
32
  activerecord (>= 3.0.0)
32
33
  activesupport (>= 3.0.0)
@@ -39,6 +40,14 @@ GEM
39
40
  ruby-hmac (~> 0.4.0)
40
41
  rest-client (1.6.7)
41
42
  mime-types (>= 1.16)
43
+ rspec (2.11.0)
44
+ rspec-core (~> 2.11.0)
45
+ rspec-expectations (~> 2.11.0)
46
+ rspec-mocks (~> 2.11.0)
47
+ rspec-core (2.11.0)
48
+ rspec-expectations (2.11.1)
49
+ diff-lcs (~> 1.1.3)
50
+ rspec-mocks (2.11.1)
42
51
  ruby-hmac (0.4.0)
43
52
  tzinfo (0.3.33)
44
53
 
@@ -47,3 +56,4 @@ PLATFORMS
47
56
 
48
57
  DEPENDENCIES
49
58
  paperclip-qiniu!
59
+ rspec
data/README.md CHANGED
@@ -1,21 +1,25 @@
1
1
  # Paperclip::Qiniu
2
2
 
3
- storage paperclip attachments to http://qiniutek.com
3
+ storage [paperclip](https://github.com/thoughtbot/paperclip/) attachments to http://qiniutek.com
4
+
5
+ example project: https://github.com/lidaobing/paperclip-qiniu-example
6
+
7
+ example site: http://stark-cloud-4321.herokuapp.com/
4
8
 
5
9
  ## Usage
6
10
 
7
- 0. confirm you are working on a rails app
11
+ * confirm you are working on a rails app
8
12
 
9
- 1. add following line to `Gemfile`
13
+ * add following line to `Gemfile`
10
14
 
11
- ```
15
+ ```ruby
12
16
  gem 'paperclip'
13
17
  gem 'paperclip-qiniu'
14
18
  ```
15
19
 
16
- 2. edit your `config/application.rb`
20
+ * edit your `config/application.rb`
17
21
 
18
- ```
22
+ ```ruby
19
23
  module PaperclipQiniuExample
20
24
  class Application < Rails::Application
21
25
  # ....
@@ -25,18 +29,21 @@ module PaperclipQiniuExample
25
29
  :secret_key => ENV['QINIU_SECRET_KEY'] || raise("set env QINIU_SECRET_KEY")
26
30
  },
27
31
  :bucket => "paperclip-qiniu-example",
28
- :use_timestamp => false
32
+ :use_timestamp => false, # required, and must be set to false
33
+ :qiniu_host => "cdn.example.com" # optional
29
34
  }
30
35
  end
31
36
  end
32
37
  ```
33
38
 
34
- 3. add a model like this
39
+ for more information on `qiniu_host`, read http://docs.qiniutek.com/v2/sdk/ruby/#publish
35
40
 
36
- ```
41
+ * add a model like this
42
+
43
+ ```ruby
37
44
  class Image < ActiveRecord::Base
38
45
  attr_accessible :file
39
- has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }
46
+ has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :path => ":class/:attachment/:id/:style/:basename.:extension"
40
47
  validates :file, :attachment_presence => true
41
48
  end
42
49
  ```
@@ -48,3 +55,14 @@ end
48
55
  3. Commit your changes (`git commit -am 'Added some feature'`)
49
56
  4. Push to the branch (`git push origin my-new-feature`)
50
57
  5. Create new Pull Request
58
+
59
+ ## CHANGELOG
60
+
61
+ ### 0.0.2 (2012-07-17)
62
+
63
+ * support public host.
64
+
65
+ ### 0.0.1
66
+
67
+ * it works.
68
+
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Qiniu
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -53,9 +53,16 @@ module Paperclip
53
53
 
54
54
  def public_url(style = default_style)
55
55
  init
56
- res = ::Qiniu::RS.get(bucket, path(style))
57
- return res["url"] if res
58
- nil
56
+ if @options[:qiniu_host]
57
+ "#{dynamic_fog_host_for_style(style)}/#{path(style)}"
58
+ else
59
+ res = ::Qiniu::RS.get(bucket, path(style))
60
+ if res
61
+ res["url"]
62
+ else
63
+ nil
64
+ end
65
+ end
59
66
  end
60
67
 
61
68
  private
@@ -75,12 +82,19 @@ module Paperclip
75
82
  :mime_type => file.content_type,
76
83
  :enable_crc32_check => true}
77
84
  ::Qiniu::RS.upload opts
78
- log ::Qiniu::RS.get(bucket, path)
79
85
  end
80
86
 
81
87
  def bucket
82
88
  @options[:bucket] || raise("bucket is nil")
83
89
  end
90
+
91
+ def dynamic_fog_host_for_style(style)
92
+ if @options[:qiniu_host].respond_to?(:call)
93
+ @options[:qiniu_host].call(self)
94
+ else
95
+ @options[:qiniu_host]
96
+ end
97
+ end
84
98
  end
85
99
  end
86
100
  end
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Paperclip::Qiniu::VERSION
17
17
  gem.add_dependency 'paperclip'
18
18
  gem.add_dependency 'qiniu-rs'
19
+ gem.add_development_dependency 'rspec'
19
20
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'paperclip/storage/qiniu'
3
+
4
+ module Paperclip::Storage
5
+ describe Qiniu do
6
+ context 'exists?' do
7
+ pending "it's hard to test paperclip plugin"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: paperclip plugin for qiniu
47
63
  email:
48
64
  - lidaobing@gmail.com
@@ -51,6 +67,7 @@ extensions: []
51
67
  extra_rdoc_files: []
52
68
  files:
53
69
  - .gitignore
70
+ - .rspec
54
71
  - Gemfile
55
72
  - Gemfile.lock
56
73
  - LICENSE
@@ -60,6 +77,8 @@ files:
60
77
  - lib/paperclip-qiniu/version.rb
61
78
  - lib/paperclip/storage/qiniu.rb
62
79
  - paperclip-qiniu.gemspec
80
+ - spec/lib/paperclip/storage/qiniu_spec.rb
81
+ - spec/spec_helper.rb
63
82
  homepage: https://github.com/lidaobing/paperclip-qiniu
64
83
  licenses: []
65
84
  post_install_message:
@@ -84,5 +103,7 @@ rubygems_version: 1.8.23
84
103
  signing_key:
85
104
  specification_version: 3
86
105
  summary: paperclip plugin for qiniu
87
- test_files: []
106
+ test_files:
107
+ - spec/lib/paperclip/storage/qiniu_spec.rb
108
+ - spec/spec_helper.rb
88
109
  has_rdoc: