carrierwave 0.5.8 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require "active_support/json"
4
+ require "active_support/core_ext/hash"
5
+
6
+ module CarrierWave
7
+ module Uploader
8
+ module Serialization
9
+ extend ActiveSupport::Concern
10
+
11
+ def serializable_hash
12
+ {"url" => url}.merge Hash[versions.map { |name, version| [name, { "url" => version.url }] }]
13
+ end
14
+
15
+ def as_json(options=nil)
16
+ Hash[mounted_as || "uploader", serializable_hash]
17
+ end
18
+
19
+ def to_json
20
+ ActiveSupport::JSON.encode(as_json)
21
+ end
22
+
23
+ def to_xml(options={})
24
+ merged_options = options.merge(:root => mounted_as || "uploader", :type => 'uploader')
25
+ serializable_hash.to_xml(merged_options)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -79,8 +79,6 @@ module CarrierWave
79
79
  # Ignore: path is not a dir
80
80
  rescue Errno::ENOTEMPTY, Errno::EEXIST
81
81
  # Ignore: dir is not empty
82
- rescue SystemCallError
83
- # no such directory on JRuby
84
82
  end
85
83
  end
86
84
  end
@@ -7,39 +7,24 @@ module CarrierWave
7
7
  include CarrierWave::Uploader::Configuration
8
8
 
9
9
  ##
10
+ # === Parameters
11
+ #
12
+ # [Hash] optional, the query params (only AWS)
13
+ #
10
14
  # === Returns
11
15
  #
12
16
  # [String] the location where this file is accessible via a url
13
17
  #
14
- def url
18
+ def url(options = {})
15
19
  if file.respond_to?(:url) and not file.url.blank?
16
- file.url
20
+ file.method(:url).arity == 0 ? file.url : file.url(options)
17
21
  elsif current_path
18
22
  (base_path || "") + File.expand_path(current_path).gsub(File.expand_path(root), '')
19
23
  end
20
24
  end
21
25
 
22
- alias_method :to_s, :url
23
-
24
- ##
25
- # === Returns
26
- #
27
- # [Hash] the locations where this file and versions are accessible via a url
28
- #
29
- def as_json(options = nil)
30
- h = { :url => url }
31
- h.merge Hash[versions.map { |name, version| [name, { :url => version.url }] }]
32
- end
33
-
34
- ##
35
- # FIXME to_xml should work like to_json, but this is the best we've been able to do so far.
36
- # This hack fixes issue #337.
37
- #
38
- # === Returns
39
- #
40
- # [nil]
41
- #
42
- def to_xml(options = nil)
26
+ def to_s
27
+ url || ''
43
28
  end
44
29
 
45
30
  end # Url
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'active_support/deprecation'
4
-
5
3
  module CarrierWave
6
4
  module Uploader
7
5
  module Versions
@@ -10,18 +8,7 @@ module CarrierWave
10
8
  include CarrierWave::Uploader::Callbacks
11
9
 
12
10
  included do
13
- ##
14
- # Add configuration options for versions
15
- # class_inheritable_accessor was deprecated in Rails 3.1 and removed for 3.2.
16
- # class_attribute was added in 3.0, but doesn't support omitting the instance_reader until 3.0.10
17
- # For max compatibility, always use class_inheritable_accessor when possible
18
- if respond_to?(:class_inheritable_accessor)
19
- ActiveSupport::Deprecation.silence do
20
- class_inheritable_accessor :versions, :version_names, :instance_reader => false, :instance_writer => false
21
- end
22
- else
23
- class_attribute :versions, :version_names, :instance_reader => false, :instance_writer => false
24
- end
11
+ class_attribute :versions, :version_names, :instance_reader => false, :instance_writer => false
25
12
 
26
13
  self.versions = {}
27
14
  self.version_names = []
@@ -140,28 +127,36 @@ module CarrierWave
140
127
  ##
141
128
  # When given a version name as a parameter, will return the url for that version
142
129
  # This also works with nested versions.
130
+ # When given a query hash as a parameter, will return the url with signature that contains query params
131
+ # Query hash only works with AWS (S3 storage).
143
132
  #
144
133
  # === Example
145
134
  #
146
135
  # my_uploader.url # => /path/to/my/uploader.gif
147
136
  # my_uploader.url(:thumb) # => /path/to/my/thumb_uploader.gif
148
137
  # my_uploader.url(:thumb, :small) # => /path/to/my/thumb_small_uploader.gif
138
+ # my_uploader.url(:query => {"response-content-disposition" => "attachment"})
139
+ # my_uploader.url(:version, :sub_version, :query => {"response-content-disposition" => "attachment"})
149
140
  #
150
141
  # === Parameters
151
142
  #
152
143
  # [*args (Symbol)] any number of versions
144
+ # OR/AND
145
+ # [Hash] query params
153
146
  #
154
147
  # === Returns
155
148
  #
156
149
  # [String] the location where this file is accessible via a url
157
150
  #
158
151
  def url(*args)
159
- if(args.first)
160
- raise ArgumentError, "Version #{args.first} doesn't exist!" if versions[args.first.to_sym].nil?
152
+ if (version = args.first) && version.respond_to?(:to_sym)
153
+ raise ArgumentError, "Version #{version} doesn't exist!" if versions[version.to_sym].nil?
161
154
  # recursively proxy to version
162
- versions[args.first.to_sym].url(*args[1..-1])
155
+ versions[version.to_sym].url(*args[1..-1])
156
+ elsif args.first
157
+ super(args.first)
163
158
  else
164
- super()
159
+ super
165
160
  end
166
161
  end
167
162
 
@@ -191,7 +186,15 @@ module CarrierWave
191
186
  def active_versions
192
187
  versions.select do |name, uploader|
193
188
  condition = self.class.versions[name][:options][:if]
194
- not condition or send(condition, file)
189
+ if(condition)
190
+ if(condition.respond_to?(:call))
191
+ condition.call(self, :version => name, :file => file)
192
+ else
193
+ send(condition, file)
194
+ end
195
+ else
196
+ true
197
+ end
195
198
  end
196
199
  end
197
200
 
@@ -211,8 +214,22 @@ module CarrierWave
211
214
  :filename => new_file.original_filename
212
215
 
213
216
  active_versions.each do |name, v|
217
+ next if v.cached?
218
+
219
+ # If option :from_version is present, create cache using cached file from
220
+ # version indicated
221
+ if self.class.versions[name][:options] && self.class.versions[name][:options][:from_version]
222
+ # Maybe the reference version has not been cached yet
223
+ unless versions[self.class.versions[name][:options][:from_version]].cached?
224
+ versions[self.class.versions[name][:options][:from_version]].cache!(processed_parent)
225
+ end
226
+ processed_version = SanitizedFile.new :tempfile => versions[self.class.versions[name][:options][:from_version]],
227
+ :filename => new_file.original_filename
228
+ v.cache!(processed_version)
229
+ else
230
+ v.cache!(processed_parent)
231
+ end
214
232
  v.send(:cache_id=, cache_id)
215
- v.cache!(processed_parent)
216
233
  end
217
234
  end
218
235
 
@@ -3,7 +3,6 @@
3
3
  require 'active_model/validator'
4
4
  require 'active_support/concern'
5
5
 
6
-
7
6
  module CarrierWave
8
7
 
9
8
  # == Active Model Presence Validator
@@ -61,4 +60,4 @@ module CarrierWave
61
60
  end
62
61
  end
63
62
 
64
- I18n.load_path << File.join(File.dirname(__FILE__), "..", "locale", 'en.yml')
63
+ I18n.load_path << File.join(File.dirname(__FILE__), "..", "locale", 'en.yml')
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.5.8"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -6,6 +6,10 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
6
6
  # include CarrierWave::RMagick
7
7
  # include CarrierWave::MiniMagick
8
8
 
9
+ # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
10
+ # include Sprockets::Helpers::RailsHelper
11
+ # include Sprockets::Helpers::IsolatedHelper
12
+
9
13
  # Choose what kind of storage to use for this uploader:
10
14
  storage :file
11
15
  # storage :fog
@@ -18,6 +22,9 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
18
22
 
19
23
  # Provide a default URL as a default if there hasn't been a file uploaded:
20
24
  # def default_url
25
+ # # For Rails 3.1+ asset pipeline compatibility:
26
+ # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
27
+ #
21
28
  # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
22
29
  # end
23
30
 
metadata CHANGED
@@ -1,204 +1,157 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 8
10
- version: 0.5.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jonas Nicklas
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-10 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activesupport
16
+ requirement: &70154105280420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *70154105280420
25
+ - !ruby/object:Gem::Dependency
26
+ name: activemodel
27
+ requirement: &70154105279720 !ruby/object:Gem::Requirement
26
28
  none: false
27
- requirements:
28
- - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 3
33
- - 0
34
- version: "3.0"
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rails
38
- type: :development
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.2.0
33
+ type: :runtime
39
34
  prerelease: false
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *70154105279720
36
+ - !ruby/object:Gem::Dependency
37
+ name: mysql2
38
+ requirement: &70154105279120 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 3
48
- - 0
49
- version: "3.0"
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: sqlite3
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
53
44
  type: :development
54
45
  prerelease: false
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *70154105279120
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: &70154105278160 !ruby/object:Gem::Requirement
56
50
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
64
- requirement: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: cucumber
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
67
55
  type: :development
68
56
  prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: *70154105278160
58
+ - !ruby/object:Gem::Dependency
59
+ name: cucumber
60
+ requirement: &70154105277620 !ruby/object:Gem::Requirement
70
61
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
78
- requirement: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: json
62
+ requirements:
63
+ - - =
64
+ - !ruby/object:Gem::Version
65
+ version: 1.1.4
81
66
  type: :development
82
67
  prerelease: false
83
- version_requirements: &id005 !ruby/object:Gem::Requirement
68
+ version_requirements: *70154105277620
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: &70154105277040 !ruby/object:Gem::Requirement
84
72
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
- requirement: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: rspec
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
95
77
  type: :development
96
78
  prerelease: false
97
- version_requirements: &id006 !ruby/object:Gem::Requirement
79
+ version_requirements: *70154105277040
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70154105272120 !ruby/object:Gem::Requirement
98
83
  none: false
99
- requirements:
84
+ requirements:
100
85
  - - ~>
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 2
105
- - 0
106
- version: "2.0"
107
- requirement: *id006
108
- - !ruby/object:Gem::Dependency
109
- name: sham_rack
86
+ - !ruby/object:Gem::Version
87
+ version: '2.0'
110
88
  type: :development
111
89
  prerelease: false
112
- version_requirements: &id007 !ruby/object:Gem::Requirement
90
+ version_requirements: *70154105272120
91
+ - !ruby/object:Gem::Dependency
92
+ name: sham_rack
93
+ requirement: &70154105271520 !ruby/object:Gem::Requirement
113
94
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
121
- requirement: *id007
122
- - !ruby/object:Gem::Dependency
123
- name: timecop
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
124
99
  type: :development
125
100
  prerelease: false
126
- version_requirements: &id008 !ruby/object:Gem::Requirement
101
+ version_requirements: *70154105271520
102
+ - !ruby/object:Gem::Dependency
103
+ name: timecop
104
+ requirement: &70154105270720 !ruby/object:Gem::Requirement
127
105
  none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
- version: "0"
135
- requirement: *id008
136
- - !ruby/object:Gem::Dependency
137
- name: cloudfiles
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
138
110
  type: :development
139
111
  prerelease: false
140
- version_requirements: &id009 !ruby/object:Gem::Requirement
141
- none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
149
- requirement: *id009
150
- - !ruby/object:Gem::Dependency
112
+ version_requirements: *70154105270720
113
+ - !ruby/object:Gem::Dependency
151
114
  name: fog
115
+ requirement: &70154105269600 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 1.3.1
152
121
  type: :development
153
122
  prerelease: false
154
- version_requirements: &id010 !ruby/object:Gem::Requirement
155
- none: false
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
- version: "0"
163
- requirement: *id010
164
- - !ruby/object:Gem::Dependency
123
+ version_requirements: *70154105269600
124
+ - !ruby/object:Gem::Dependency
165
125
  name: mini_magick
126
+ requirement: &70154105269140 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
166
132
  type: :development
167
133
  prerelease: false
168
- version_requirements: &id011 !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
175
- - 0
176
- version: "0"
177
- requirement: *id011
178
- - !ruby/object:Gem::Dependency
134
+ version_requirements: *70154105269140
135
+ - !ruby/object:Gem::Dependency
179
136
  name: rmagick
137
+ requirement: &70154105268620 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
180
143
  type: :development
181
144
  prerelease: false
182
- version_requirements: &id012 !ruby/object:Gem::Requirement
183
- none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
191
- requirement: *id012
192
- description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
193
- email:
145
+ version_requirements: *70154105268620
146
+ description: Upload files in your Ruby applications, map them to a range of ORMs,
147
+ store them on different backends.
148
+ email:
194
149
  - jonas.nicklas@gmail.com
195
150
  executables: []
196
-
197
151
  extensions: []
198
-
199
- extra_rdoc_files:
152
+ extra_rdoc_files:
200
153
  - README.md
201
- files:
154
+ files:
202
155
  - lib/carrierwave/compatibility/paperclip.rb
203
156
  - lib/carrierwave/locale/en.yml
204
157
  - lib/carrierwave/mount.rb
@@ -208,11 +161,8 @@ files:
208
161
  - lib/carrierwave/processing/rmagick.rb
209
162
  - lib/carrierwave/sanitized_file.rb
210
163
  - lib/carrierwave/storage/abstract.rb
211
- - lib/carrierwave/storage/cloud_files.rb
212
164
  - lib/carrierwave/storage/file.rb
213
165
  - lib/carrierwave/storage/fog.rb
214
- - lib/carrierwave/storage/right_s3.rb
215
- - lib/carrierwave/storage/s3.rb
216
166
  - lib/carrierwave/test/matchers.rb
217
167
  - lib/carrierwave/uploader/cache.rb
218
168
  - lib/carrierwave/uploader/callbacks.rb
@@ -224,6 +174,7 @@ files:
224
174
  - lib/carrierwave/uploader/processing.rb
225
175
  - lib/carrierwave/uploader/proxy.rb
226
176
  - lib/carrierwave/uploader/remove.rb
177
+ - lib/carrierwave/uploader/serialization.rb
227
178
  - lib/carrierwave/uploader/store.rb
228
179
  - lib/carrierwave/uploader/url.rb
229
180
  - lib/carrierwave/uploader/versions.rb
@@ -234,39 +185,29 @@ files:
234
185
  - lib/generators/templates/uploader.rb
235
186
  - lib/generators/uploader_generator.rb
236
187
  - README.md
237
- has_rdoc: true
238
188
  homepage: https://github.com/jnicklas/carrierwave
239
189
  licenses: []
240
-
241
190
  post_install_message:
242
- rdoc_options:
191
+ rdoc_options:
243
192
  - --main
244
- require_paths:
193
+ require_paths:
245
194
  - lib
246
- required_ruby_version: !ruby/object:Gem::Requirement
195
+ required_ruby_version: !ruby/object:Gem::Requirement
247
196
  none: false
248
- requirements:
249
- - - ">="
250
- - !ruby/object:Gem::Version
251
- hash: 3
252
- segments:
253
- - 0
254
- version: "0"
255
- required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ! '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
256
202
  none: false
257
- requirements:
258
- - - ">="
259
- - !ruby/object:Gem::Version
260
- hash: 3
261
- segments:
262
- - 0
263
- version: "0"
203
+ requirements:
204
+ - - ! '>='
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
264
207
  requirements: []
265
-
266
208
  rubyforge_project: carrierwave
267
- rubygems_version: 1.6.2
209
+ rubygems_version: 1.8.10
268
210
  signing_key:
269
211
  specification_version: 3
270
212
  summary: Ruby file upload library
271
213
  test_files: []
272
-