carrierwave-qiniu 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04640c52f6176337abf13494a126a5c1aee37a08
4
- data.tar.gz: 53058125653be7c0cdef610f133cbeccb5b43fb5
3
+ metadata.gz: b044a1ac28aea84db7adb5190619a2de43ee8cc0
4
+ data.tar.gz: 6b4edd18e16dc3f09123bf534c6f30378c6b7160
5
5
  SHA512:
6
- metadata.gz: 7c711e6520f752659341b048433fb63c1c59c6d96cad26d62416e09351a20e6f8c408b1d582bfadc3fcf566790b8b6bb57c930da5010352eb4924262de6afb9b
7
- data.tar.gz: fa0fcef504448c964e769c39d4ce531650caa12b6e76cd0fc0a027c0bee1a0e13be8db53b25e77049b595e4e7ebc49dfe8070304bc5d6faa4c8711d05561d4b5
6
+ metadata.gz: 52fcfbbdfd26eb4faf7f6f0be932503d1c61c59b208be441e7b96b4e0032ffb379816f170d01ec474a53c64da09fc91b10da2c2fc7c93f141be62051cfa1aa2a
7
+ data.tar.gz: 2171171a2c871055ba0276d706f90473d5c071230c93a98dd3f757f8844837123f3e5c070bd4e9b75f1228780f73747cc9895f567dd42270a2643fa88592ad6d
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ group :test do
9
9
  gem 'sqlite3', '>=1.3.6'
10
10
  gem 'carrierwave', '>=0.6.2'
11
11
  gem 'mini_magick', '>=3.4'
12
- gem 'qiniu-rs', '>=3.0.3'
12
+ gem 'qiniu-rs', '~>3.4.2'
13
13
  gem 'rspec', '~> 2.11'
14
14
  gem 'mocha', '>=0.10.0'
15
15
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 huobazi
1
+ Copyright (c) 2012 Marble Wu
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -30,7 +30,7 @@ You'll need to configure it in config/initializes/carrierwave.rb
30
30
  config.qiniu_bucket = "carrierwave-qiniu-example"
31
31
  config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
32
32
  config.qiniu_block_size = 4*1024*1024
33
- config.qiniu_protocal = "http"
33
+ config.qiniu_protocol = "http"
34
34
  end
35
35
  ```
36
36
 
@@ -52,6 +52,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
52
52
 
53
53
  self.qiniu_bucket = "avatars"
54
54
  self.qiniu_bucket_domain = "avatars.files.example.com"
55
+ self.qiniu_protocal = 'http'
56
+ self.qiniu_can_overwrite = true
55
57
 
56
58
  # See also:
57
59
  # https://github.com/qiniu/ruby-sdk/issues/48
@@ -2,11 +2,12 @@
2
2
  require File.expand_path('../lib/carrierwave-qiniu/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["huobazi"]
5
+ gem.authors = ["Marble Wu"]
6
6
  gem.email = ["huobazi@gmail.com"]
7
7
  gem.description = %q{Qiniu Storage support for CarrierWave}
8
8
  gem.summary = %q{Qiniu Storage support for CarrierWave}
9
9
  gem.homepage = "https://github.com/huobazi/carrierwave-qiniu"
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -10,31 +10,30 @@ module CarrierWave
10
10
  add_config :qiniu_access_key
11
11
  add_config :qiniu_secret_key
12
12
  add_config :qiniu_block_size
13
- add_config :qiniu_protocal
13
+ add_config :qiniu_protocol
14
+ add_config :qiniu_async_ops
15
+ add_config :qiniu_can_overwrite
16
+
17
+ alias_config :qiniu_protocal, :qiniu_protocol
14
18
  end
15
- end
16
19
 
17
- module ClassMethods
18
- def add_config(name)
20
+ module ClassMethods
21
+ def alias_config(new_name, old_name)
19
22
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
20
- def self.#{name}(value=nil)
21
- @#{name} = value if value
22
- return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
23
- name = superclass.#{name}
24
- return nil if name.nil? && !instance_variable_defined?("@#{name}")
25
- @#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
26
- end
23
+ def self.#{new_name}(value=nil)
24
+ self.#{old_name}(value)
25
+ end
27
26
 
28
- def self.#{name}=(value)
29
- @#{name} = value
30
- end
27
+ def self.#{new_name}=(value)
28
+ self.#{old_name}=(value)
29
+ end
31
30
 
32
- def #{name}
33
- value = self.class.#{name}
34
- value.instance_of?(Proc) ? value.call : value
35
- end
31
+ def #{new_name}
32
+ #{old_name}
33
+ end
36
34
  RUBY
37
35
  end
36
+ end
38
37
  end
39
38
  end
40
39
  end
@@ -13,14 +13,17 @@ module CarrierWave
13
13
  @qiniu_access_key = options[:qiniu_access_key]
14
14
  @qiniu_secret_key = options[:qiniu_secret_key]
15
15
  @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
16
- @qiniu_protocal = options[:qiniu_protocal] || "http"
16
+ @qiniu_protocol = options[:qiniu_protocol] || options[:qiniu_protocal] || "http"
17
17
  @qiniu_async_ops = options[:qiniu_async_ops] || ''
18
+ @qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
18
19
  init
19
20
  end
20
21
 
21
22
  def store(file, key)
23
+ qiniu_upload_scope = @qiniu_bucket
24
+ qiniu_upload_scope = @qiniu_bucket + ':' + key if @qiniu_can_overwrite
22
25
  token_opts = {
23
- :scope => @qiniu_bucket, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
26
+ :scope => qiniu_upload_scope, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
24
27
  }
25
28
  token_opts.merge!(:async_options => @qiniu_async_ops) if @qiniu_async_ops.size > 0
26
29
 
@@ -49,7 +52,7 @@ module CarrierWave
49
52
 
50
53
  def get_public_url(key)
51
54
  if @qiniu_bucket_domain and @qiniu_bucket_domain.size > 0
52
- "#{@qiniu_protocal}://#{@qiniu_bucket_domain}/#{key}"
55
+ "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{key}"
53
56
  else
54
57
  res = ::Qiniu::RS.get(@qiniu_bucket, key)
55
58
  if res
@@ -93,7 +96,7 @@ module CarrierWave
93
96
 
94
97
  def url
95
98
  if @uploader.qiniu_bucket_domain and @uploader.qiniu_bucket_domain.size > 0
96
- "#{@uploader.qiniu_protocal || 'http'}://#{@uploader.qiniu_bucket_domain}/#{@path}"
99
+ "#{@uploader.qiniu_protocol || 'http'}://#{@uploader.qiniu_bucket_domain}/#{@path}"
97
100
  else
98
101
  qiniu_connection.get_public_url(@path)
99
102
  end
@@ -119,7 +122,7 @@ module CarrierWave
119
122
  :qiniu_bucket => @uploader.qiniu_bucket,
120
123
  :qiniu_bucket_domain => @uploader.qiniu_bucket_domain,
121
124
  :qiniu_block_size => @uploader.qiniu_block_size,
122
- :qiniu_protocal => @uploader.qiniu_protocal
125
+ :qiniu_protocol => @uploader.qiniu_protocol
123
126
  }
124
127
 
125
128
  if @uploader.respond_to?(:qiniu_async_ops) and !@uploader.qiniu_async_ops.nil? and @uploader.qiniu_async_ops.size > 0
@@ -130,6 +133,14 @@ module CarrierWave
130
133
  end
131
134
  end
132
135
 
136
+ if @uploader.respond_to?(:qiniu_can_overwrite) and !@uploader.qiniu_can_overwrite.nil?
137
+ if @uploader.qiniu_can_overwrite.is_a?(TrueClass) or @uploader.is_a?(FalseClass)
138
+ config.merge!(:qiniu_can_overwrite => @uploader.qiniu_can_overwrite)
139
+ else
140
+ config.merge!(:qiniu_can_overwrite => false)
141
+ end
142
+ end
143
+
133
144
  @qiniu_connection ||= Connection.new config
134
145
  end
135
146
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
6
6
  end
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,7 @@ ActiveRecord::Migration.verbose = false
30
30
  config.qiniu_bucket = "spec-test"
31
31
  config.qiniu_bucket_domain = "spec-test.qiniudn.com"
32
32
  config.qiniu_block_size = 4*1024*1024
33
- config.qiniu_protocal = "http"
33
+ config.qiniu_protocol = "http"
34
34
  end
35
35
 
36
36
  def load_file(fname)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
- - huobazi
7
+ - Marble Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-11 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -59,7 +59,8 @@ files:
59
59
  - spec/spec_helper.rb
60
60
  - spec/upload_spec.rb
61
61
  homepage: https://github.com/huobazi/carrierwave-qiniu
62
- licenses: []
62
+ licenses:
63
+ - MIT
63
64
  metadata: {}
64
65
  post_install_message:
65
66
  rdoc_options: []
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  requirements: []
79
80
  rubyforge_project:
80
- rubygems_version: 2.0.3
81
+ rubygems_version: 2.2.2
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Qiniu Storage support for CarrierWave