mender_paperclip 2.4.3 → 2.4.3.1

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/lib/paperclip.rb CHANGED
@@ -100,7 +100,6 @@ module Paperclip
100
100
  end
101
101
  command_path = options[:command_path] || options[:image_magick_path]
102
102
  Cocaine::CommandLine.path = ( Cocaine::CommandLine.path ? [Cocaine::CommandLine.path, command_path ].flatten : command_path )
103
- Cocaine::CommandLine.logger = logger
104
103
  Cocaine::CommandLine.new(cmd, *params).run
105
104
  end
106
105
 
@@ -103,22 +103,26 @@ module Paperclip
103
103
 
104
104
  return nil if uploaded_file.nil?
105
105
 
106
- uploaded_filename ||= uploaded_file.original_filename
107
- uploaded_content_type = extract_content_type(uploaded_file)
108
- uploaded_filename = rewrite_extension(uploaded_filename, uploaded_content_type)
109
- @queued_for_write[:original] = to_tempfile(uploaded_file)
110
- instance_write(:file_name, uploaded_filename.strip)
111
- instance_write(:content_type, uploaded_content_type)
112
- instance_write(:file_size, uploaded_file.size.to_i)
113
- instance_write(:fingerprint, generate_fingerprint(uploaded_file))
114
- instance_write(:updated_at, Time.now)
106
+ uploaded_filename ||= uploaded_file.original_filename
107
+ @queued_for_write[:original] = to_tempfile(uploaded_file)
108
+ uploaded_content_type = extract_content_type(@queued_for_write[:original])
109
+ instance_write(:file_name, uploaded_filename.strip)
110
+ instance_write(:content_type, uploaded_content_type)
111
+ instance_write(:file_size, @queued_for_write[:original].size.to_i)
112
+ instance_write(:fingerprint, generate_fingerprint(uploaded_file))
113
+ instance_write(:updated_at, Time.now)
114
+
115
+ if valid_media_type?(format_content_type)
116
+ instance_write(:file_name, real_filename)
117
+ instance_write(:content_type, format_content_type)
118
+ end
115
119
 
116
120
  @dirty = true
117
121
 
118
122
  post_process(*@options.only_process) if post_processing
119
123
 
120
124
  # Reset the file size if the original file was reprocessed.
121
- instance_write(:file_size, @queued_for_write[:original].size.to_i)
125
+ #instance_write(:file_size, @queued_for_write[:original].size.to_i)
122
126
  instance_write(:fingerprint, generate_fingerprint(@queued_for_write[:original]))
123
127
  ensure
124
128
  uploaded_file.close if close_uploaded_file
@@ -253,9 +257,9 @@ module Paperclip
253
257
 
254
258
  def extract_content_type(source)
255
259
  if @options.use_file_command && source.respond_to?(:type_from_file_command)
256
- source.type_from_file_command
260
+ source.type_from_file_command.to_s.strip
257
261
  elsif source.respond_to?(:content_type)
258
- source.content_type
262
+ source.content_type.to_s.strip
259
263
  else
260
264
  nil
261
265
  end
@@ -329,29 +333,55 @@ module Paperclip
329
333
 
330
334
  private
331
335
 
332
- def rewrite_extension(original_filename, content_type)
333
- original_extension = File.extname(original_filename)
334
- original_basename = File.basename(original_filename, original_extension)
335
- original_extension = original_extension.sub(/^\.+/, '')
336
-
337
- mime_type = MIME::Types[content_type]
338
- extensions = mime_type.empty? ? [] : mime_type.first.extensions
339
- extension = if extensions.include?(original_extension)
340
- original_extension
341
- elsif extensions.present?
342
- extensions.first
336
+ def real_filename
337
+ original_filename = self.original_filename or return
338
+ original_content_type = self.content_type or return original_filename
339
+ original_extension = File.extname(original_filename)
340
+ original_basename = File.basename(original_filename, original_extension)
341
+ original_extension = original_extension.sub(/^\.+/, '')
342
+
343
+ mime_type = MIME::Types[original_content_type]
344
+ extensions = mime_type.empty? ? [] : mime_type.first.extensions
345
+
346
+ formats = ((style = styles[:original]) && style[:formats]) || []
347
+ if formats.present?
348
+ extension = (formats & extensions || []).first || formats.first
343
349
  else
344
- %r{/([^/]*)$}.match(content_type)[1]
350
+ extension = if extensions.include?(original_extension)
351
+ original_extension
352
+ elsif extensions.present?
353
+ extensions.first
354
+ end
345
355
  end
346
- puts "#{original_filename} #{content_type} #{extension}"
347
356
 
348
- if extension.present? && original_extension != extension
357
+ if extension.present?
349
358
  original_basename + '.' + extension
350
359
  else
351
360
  original_filename
352
361
  end
353
362
  end
354
363
 
364
+ def format_content_type
365
+ content_type = self.content_type
366
+ filename = self.original_filename or return content_type
367
+
368
+ if (types = MIME::Types.type_for(filename)).present?
369
+ types.first.content_type
370
+ else
371
+ content_type
372
+ end
373
+ end
374
+
375
+ def valid_media_type?(content_type)
376
+ original_content_type = self.content_type
377
+
378
+ original_content_type = MIME::Type.new(original_content_type) if original_content_type.is_a?(String)
379
+ content_type = MIME::Type.new(content_type) if content_type.is_a?(String)
380
+ return false unless content_type.respond_to?(:media_type)
381
+
382
+ original_content_type.blank? || (original_content_type.media_type == content_type.media_type)
383
+ end
384
+
355
385
  def ensure_required_accessors! #:nodoc:
356
386
  %w(file_name).each do |field|
357
387
  unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=")
@@ -93,18 +93,12 @@ module Paperclip
93
93
  # If the style has a format defined, it will return the format instead
94
94
  # of the actual extension.
95
95
  def extension attachment, style_name
96
- style = attachment.styles[style_name]
97
- ext = (style && style[:format]) || File.extname(attachment.original_filename).gsub(/^\.+/, "")
98
-
99
- if style && (except_formats = style[:except_formats])
100
- except_formats = except_formats.split(/\s+/) if except_formats.respond_to?(:split)
101
- original_ext = File.extname(attachment.original_filename).gsub(/^\.+/, "")
102
- ext = original_ext if except_formats.include?(original_ext)
96
+ if !attachment.instance.respond_to?(:created_at) || attachment.instance.created_at <= Time.utc(2011, 10, 17, 8, 30, 0)
97
+ return File.extname(attachment.original_filename).gsub(/^\.+/, "")
103
98
  end
104
99
 
105
- ext
106
- #((style = attachment.styles[style_name]) && style[:format]) ||
107
- # File.extname(attachment.original_filename).gsub(/^\.+/, "")
100
+ ((style = attachment.styles[style_name]) && style[:format]) ||
101
+ File.extname(attachment.original_filename).gsub(/^\.+/, "")
108
102
  end
109
103
 
110
104
  # Returns an extension based on the content type. e.g. "jpeg" for "image/jpeg".
@@ -6,7 +6,7 @@ module Paperclip
6
6
 
7
7
  class Style
8
8
 
9
- attr_reader :name, :attachment, :format
9
+ attr_reader :name, :attachment, :formats
10
10
 
11
11
  # Creates a Style object. +name+ is the name of the attachment,
12
12
  # +definition+ is the style definition from has_attached_file, which
@@ -16,7 +16,7 @@ module Paperclip
16
16
  @attachment = attachment
17
17
  if definition.is_a? Hash
18
18
  @geometry = definition.delete(:geometry)
19
- @format = definition.delete(:format)
19
+ self.format = definition.delete(:format)
20
20
  @processors = definition.delete(:processors)
21
21
  @other_args = definition
22
22
  else
@@ -76,7 +76,7 @@ module Paperclip
76
76
  # Supports getting and setting style properties with hash notation to ensure backwards-compatibility
77
77
  # eg. @attachment.options.styles[:large][:geometry]@ will still work
78
78
  def [](key)
79
- if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key)
79
+ if [:name, :convert_options, :whiny, :processors, :geometry, :format, :formats, :animated, :source_file_options].include?(key)
80
80
  send(key)
81
81
  elsif defined? @other_args[key]
82
82
  @other_args[key]
@@ -84,12 +84,26 @@ module Paperclip
84
84
  end
85
85
 
86
86
  def []=(key, value)
87
- if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key)
87
+ if [:name, :convert_options, :whiny, :processors, :geometry, :format, :formats, :animated, :source_file_options].include?(key)
88
88
  send("#{key}=".intern, value)
89
89
  else
90
90
  @other_args[key] = value
91
91
  end
92
92
  end
93
93
 
94
+ def formats=(formats)
95
+ @formats = formats.respond_to?(:split) ? formats.split(/\s+/) : formats.flatten
96
+ end
97
+ alias_method :format=, :formats=
98
+
99
+ def format
100
+ if @formats.present? && (filename = attachment.original_filename)
101
+ ext = File.extname(filename)[1..-1]
102
+ @formats.include?(ext) ? ext : @formats.first
103
+ else
104
+ nil
105
+ end
106
+ end
107
+
94
108
  end
95
109
  end
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "2.4.3" unless defined? Paperclip::VERSION
2
+ VERSION = "2.4.3.1" unless defined? Paperclip::VERSION
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mender_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-17 00:00:00.000000000 +06:00
12
+ date: 2011-12-19 00:00:00.000000000 +06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &83645350 !ruby/object:Gem::Requirement
17
+ requirement: &84797790 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *83645350
25
+ version_requirements: *84797790
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &83644570 !ruby/object:Gem::Requirement
28
+ requirement: &84797030 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.3.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *83644570
36
+ version_requirements: *84797030
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cocaine
39
- requirement: &83643880 !ruby/object:Gem::Requirement
39
+ requirement: &84796160 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.0.2
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *83643880
47
+ version_requirements: *84796160
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mime-types
50
- requirement: &83643430 !ruby/object:Gem::Requirement
50
+ requirement: &84795650 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *83643430
58
+ version_requirements: *84795650
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: shoulda
61
- requirement: &83642930 !ruby/object:Gem::Requirement
61
+ requirement: &84795140 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *83642930
69
+ version_requirements: *84795140
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: appraisal
72
- requirement: &83642370 !ruby/object:Gem::Requirement
72
+ requirement: &84794770 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *83642370
80
+ version_requirements: *84794770
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mocha
83
- requirement: &83641680 !ruby/object:Gem::Requirement
83
+ requirement: &84794290 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *83641680
91
+ version_requirements: *84794290
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: aws-s3
94
- requirement: &83607120 !ruby/object:Gem::Requirement
94
+ requirement: &84793410 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *83607120
102
+ version_requirements: *84793410
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: sqlite3
105
- requirement: &83606440 !ruby/object:Gem::Requirement
105
+ requirement: &84750510 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *83606440
113
+ version_requirements: *84750510
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: cucumber
116
- requirement: &83605830 !ruby/object:Gem::Requirement
116
+ requirement: &84749860 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *83605830
124
+ version_requirements: *84749860
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: capybara
127
- requirement: &83605470 !ruby/object:Gem::Requirement
127
+ requirement: &84749390 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,7 +132,7 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *83605470
135
+ version_requirements: *84749390
136
136
  description: Easy upload management for ActiveRecord
137
137
  email: jyurek@thoughtbot.com
138
138
  executables: []
@@ -226,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  segments:
228
228
  - 0
229
- hash: 948056321
229
+ hash: -483573327
230
230
  required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  none: false
232
232
  requirements: