pothoven-attachment_fu 3.2.15 → 3.2.16

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ * Jul 15, 2015 *
2
+ * Pull in changes from brauliobo to fix protected_attributes for Rails 4.2 *
3
+ * Acknowlegement also to malmckay who provided another elegant fix to the protected_attributes problem and I want to thank him for it, but I had to pick 1 *
4
+
1
5
  * Jan 27, 2015 *
2
6
  * Pull in changes from bacrossland to fix test suite *
3
7
 
@@ -319,17 +319,12 @@ module Technoweenie # :nodoc:
319
319
  thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
320
320
  find_or_initialize_thumbnail(file_name_suffix).tap do |thumb|
321
321
  thumb.temp_paths.unshift temp_file
322
- assign_attributes_args = []
323
- assign_attributes_args << {
324
- :content_type => content_type,
325
- :filename => thumbnail_name_for(file_name_suffix),
322
+ attributes = {
323
+ :content_type => content_type,
324
+ :filename => thumbnail_name_for(file_name_suffix),
326
325
  :thumbnail_resize_options => size
327
326
  }
328
- if defined?(Rails) && Rails::VERSION::MAJOR == 3
329
- # assign_attributes API in Rails 2.3 doesn't take a second argument
330
- assign_attributes_args << { :without_protection => true }
331
- end
332
- thumb.send(:assign_attributes, *assign_attributes_args)
327
+ attributes.each{ |a, v| thumb.send "#{a}=", v }
333
328
  callback_with_args :before_thumbnail_saved, thumb
334
329
  thumb.save!
335
330
  end
@@ -436,8 +431,8 @@ module Technoweenie # :nodoc:
436
431
  # Write out the temporary data if it is not present
437
432
  if temp_data.nil?
438
433
  self.temp_data = current_data
439
- end
440
-
434
+ end
435
+
441
436
  self.class.with_image(temp_path, &block)
442
437
  end
443
438
 
@@ -445,7 +440,7 @@ module Technoweenie # :nodoc:
445
440
  # Generates a unique filename for a Tempfile.
446
441
  def random_tempfile_filename
447
442
  base_filename = filename ? filename.gsub(/\.\w+$/, '') : 'attachment'
448
- ext = filename.slice(/\.\w+$/)
443
+ ext = filename ? filename.slice(/\.\w+$/) : ''
449
444
  ["#{rand Time.now.to_i}#{base_filename}", ext || '']
450
445
  end
451
446
 
@@ -480,15 +475,14 @@ module Technoweenie # :nodoc:
480
475
 
481
476
  # Initializes a new thumbnail with the given suffix.
482
477
  def find_or_initialize_thumbnail(file_name_suffix)
483
- if defined?(Rails) && Rails::VERSION::MAJOR >= 4
484
- respond_to?(:parent_id) ?
485
- thumbnail_class.find_or_initialize_by(:thumbnail => file_name_suffix.to_s, :parent_id => id) :
486
- thumbnail_class.find_or_initialize_by(:thumbnail => file_name_suffix.to_s)
487
- else
488
- respond_to?(:parent_id) ?
489
- thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
490
- thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
478
+ attrs = {thumbnail: file_name_suffix.to_s}
479
+ attrs[:parent_id] = id if respond_to? :parent_id
480
+ thumb = thumbnail_class.where(attrs).first
481
+ unless thumb
482
+ thumb = thumbnail_class.new
483
+ attrs.each{ |a, v| thumb[a] = v }
491
484
  end
485
+ thumb
492
486
  end
493
487
 
494
488
  # Stub for a #process_attachment method in a processor
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pothoven-attachment_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.15
4
+ version: 3.2.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-27 00:00:00.000000000 Z
13
+ date: 2015-07-15 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: This is a fork of Rick Olson's attachment_fu adding Ruby 1.9 and Rails
16
16
  3.2 and Rails 4 support as well as some other enhancements.