carrierwave 0.9.0 → 0.10.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.

Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +69 -9
  3. data/lib/carrierwave.rb +7 -0
  4. data/lib/carrierwave/compatibility/paperclip.rb +29 -19
  5. data/lib/carrierwave/locale/el.yml +11 -0
  6. data/lib/carrierwave/locale/es.yml +11 -0
  7. data/lib/carrierwave/locale/fr.yml +11 -0
  8. data/lib/carrierwave/locale/ja.yml +11 -0
  9. data/lib/carrierwave/locale/nb.yml +11 -0
  10. data/lib/carrierwave/locale/pl.yml +11 -0
  11. data/lib/carrierwave/locale/pt-BR.yml +11 -0
  12. data/lib/carrierwave/locale/pt-PT.yml +11 -0
  13. data/lib/carrierwave/locale/ru.yml +11 -0
  14. data/lib/carrierwave/locale/tr.yml +11 -0
  15. data/lib/carrierwave/mount.rb +39 -36
  16. data/lib/carrierwave/orm/activerecord.rb +1 -0
  17. data/lib/carrierwave/processing/mime_types.rb +1 -0
  18. data/lib/carrierwave/processing/mini_magick.rb +12 -5
  19. data/lib/carrierwave/processing/rmagick.rb +6 -18
  20. data/lib/carrierwave/sanitized_file.rb +6 -1
  21. data/lib/carrierwave/storage/fog.rb +6 -5
  22. data/lib/carrierwave/uploader/configuration.rb +8 -0
  23. data/lib/carrierwave/uploader/download.rb +16 -10
  24. data/lib/carrierwave/uploader/processing.rb +15 -17
  25. data/lib/carrierwave/uploader/proxy.rb +11 -0
  26. data/lib/carrierwave/uploader/serialization.rb +1 -1
  27. data/lib/carrierwave/uploader/versions.rb +45 -44
  28. data/lib/carrierwave/utilities.rb +2 -1
  29. data/lib/carrierwave/utilities/deprecation.rb +18 -0
  30. data/lib/carrierwave/validations/active_model.rb +0 -2
  31. data/lib/carrierwave/version.rb +1 -1
  32. data/lib/generators/templates/uploader.rb +1 -1
  33. data/lib/generators/uploader_generator.rb +1 -1
  34. metadata +100 -72
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0092635d7d29c1b3f6b16b2589e48ba6919ff0b9
4
+ data.tar.gz: c19c7734e547d39cfec1d90aa48fb28bd3d99b2a
5
+ SHA512:
6
+ metadata.gz: d4cce1995281a15422ac6c35b82b19b54e6ba0f5d0efffcbf6c9d3e7f81ae462efa8f313a84ba707bdf4a5e4938e7b367fae90789e18dc24421b023b64c77506
7
+ data.tar.gz: 5b103922747f4fb1f1c2a172408e9904a39930eda9cd1769ca0b9ba16ee7bbed4dbb9aa1d3a24ac8e61a19ead8491e4ed5b4bca852224f33e6b8b02a90f7d7da
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This gem provides a simple and extremely flexible way to upload files from Ruby applications.
4
4
  It works well with Rack based web applications, such as Ruby on Rails.
5
5
 
6
- [![Build Status](https://secure.travis-ci.org/carrierwaveuploader/carrierwave.png)](http://travis-ci.org/carrierwaveuploader/carrierwave)
6
+ [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.png?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
7
7
  [![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.png)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
8
8
 
9
9
  ## Information
@@ -114,7 +114,7 @@ Other ORM support has been extracted into separate gems:
114
114
 
115
115
  * [carrierwave-datamapper](https://github.com/carrierwaveuploader/carrierwave-datamapper)
116
116
  * [carrierwave-mongoid](https://github.com/carrierwaveuploader/carrierwave-mongoid)
117
- * [carrierwave-sequel](https://github.com/carrierwaveuploader/carrierwave-sequel)
117
+ * [carrierwave-sequel](https://github.com/jnicklas/carrierwave-sequel)
118
118
 
119
119
  There are more extensions listed in [the wiki](https://github.com/carrierwaveuploader/carrierwave/wiki)
120
120
 
@@ -206,12 +206,21 @@ end
206
206
 
207
207
  ## Adding versions
208
208
 
209
- Often you'll want to add different versions of the same file. The classic
210
- example is image thumbnails. There is built in support for this:
209
+ Often you'll want to add different versions of the same file. The classic example is image thumbnails. There is built in support for this*:
210
+
211
+ *Note: You must have Imagemagick and MiniMagick installed to do image resizing. MiniMagick is a Ruby interface for Imagemagick which is a C program. This is why MiniMagick fails on 'bundle install' without Imagemagick installed.
212
+
213
+ Some documentation refers to RMagick instead of MiniMagick but MiniMagick is recommended.
214
+
215
+ To install Imagemagick on OSX with homebrew type the following:
216
+
217
+ ```
218
+ $ brew install imagemagick
219
+ ```
211
220
 
212
221
  ```ruby
213
222
  class MyUploader < CarrierWave::Uploader::Base
214
- include CarrierWave::RMagick
223
+ include CarrierWave::MiniMagick
215
224
 
216
225
  process :resize_to_fit => [800, 800]
217
226
 
@@ -360,7 +369,13 @@ easily add a checkbox to the form which will remove the file when checked.
360
369
  <% end %>
361
370
  ```
362
371
 
363
- If you want to remove the file manually, you can call <code>remove_avatar!</code>.
372
+ If you want to remove the file manually, you can call <code>remove_avatar!</code>, then save the object.
373
+
374
+ ```erb
375
+ @user.remove_avatar!
376
+ @user.save
377
+ #=> true
378
+ ```
364
379
 
365
380
  ## Uploading files from a remote location
366
381
 
@@ -433,6 +448,14 @@ User.all.each do |user|
433
448
  end
434
449
  ```
435
450
 
451
+ Note: `recreate_versions!` will throw an exception on records without an image. To avoid this, scope the records to those with images or check if an image exists within the block. If you're using ActiveRecord, recreating versions for a user avatar might look like this:
452
+
453
+ ```ruby
454
+ User.all.each do |user|
455
+ user.avatar.recreate_versions! if user.avatar?
456
+ end
457
+ ```
458
+
436
459
  ## Configuring CarrierWave
437
460
 
438
461
  CarrierWave has a broad range of configuration options, which you can configure,
@@ -474,6 +497,9 @@ if Rails.env.test? or Rails.env.cucumber?
474
497
  end
475
498
  ```
476
499
 
500
+ Remember, if you have already set `storage :something` in your uploader, the `storage`
501
+ setting from this initializer will be ignored.
502
+
477
503
  If you need to test your processing, you should test it in isolation, and enable
478
504
  processing only for those tests that need it.
479
505
 
@@ -564,7 +590,7 @@ That's it! You can still use the `CarrierWave::Uploader#url` method to return th
564
590
  [Fog](http://github.com/fog/fog) is used to support Rackspace Cloud Files. Ensure you have it in your Gemfile:
565
591
 
566
592
  ```ruby
567
- gem "fog", "~> 1.10.1"
593
+ gem "fog"
568
594
  ```
569
595
 
570
596
  You'll need to configure a directory (also known as a container), username and API key in the initializer.
@@ -623,7 +649,7 @@ the url to the file on Rackspace Cloud Files.
623
649
  [Fog](http://github.com/fog/fog) is used to support Google Storage for Developers. Ensure you have it in your Gemfile:
624
650
 
625
651
  ```ruby
626
- gem "fog", "~> 1.3.1"
652
+ gem "fog"
627
653
  ```
628
654
 
629
655
  You'll need to configure a directory (also known as a bucket), access key id and secret access key in the initializer.
@@ -696,7 +722,7 @@ class AvatarUploader < CarrierWave::Uploader::Base
696
722
  process :convert => 'png'
697
723
 
698
724
  def filename
699
- super.chomp(File.extname(super)) + '.png'
725
+ super.chomp(File.extname(super)) + '.png' if original_filename.present?
700
726
  end
701
727
  end
702
728
  ```
@@ -763,6 +789,8 @@ errors:
763
789
  carrierwave_processing_error: "Cannot resize image."
764
790
  carrierwave_integrity_error: "Not an image."
765
791
  carrierwave_download_error: "Couldn't download image."
792
+ extension_white_list_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
793
+ extension_black_list_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
766
794
  ```
767
795
 
768
796
  ## Large files
@@ -788,6 +816,38 @@ When the `move_to_cache` and/or `move_to_store` methods return true, files will
788
816
 
789
817
  This has only been tested with the local filesystem store.
790
818
 
819
+ ## Skipping ActiveRecord callbacks
820
+
821
+ By default, mounting an uploader into an ActiveRecord model will add a few
822
+ callbacks. For example, this code:
823
+
824
+ ```ruby
825
+ class User
826
+ mount_uploader :avatar, AvatarUploader
827
+ end
828
+ ```
829
+
830
+ Will add these callbacks:
831
+
832
+ ```ruby
833
+ after_save :store_avatar!
834
+ before_save :write_avatar_identifier
835
+ after_commit :remove_avatar! :on => :destroy
836
+ before_update :store_previous_model_for_avatar
837
+ after_save :remove_previously_stored_avatar
838
+ ```
839
+
840
+ If you want to skip any of these callbacks (eg. you want to keep the existing
841
+ avatar, even after uploading a new one), you can use ActiveRecord’s
842
+ `skip_callback` method.
843
+
844
+ ```ruby
845
+ class User
846
+ mount_uploader :avatar, AvatarUploader
847
+ skip_callback :save, :after, :remove_previously_stored_avatar
848
+ end
849
+ ```
850
+
791
851
  ## Contributing to CarrierWave
792
852
 
793
853
  See [CONTRIBUTING.md](https://github.com/carrierwaveuploader/carrierwave/blob/master/CONTRIBUTING.md)
@@ -44,6 +44,13 @@ elsif defined?(Rails)
44
44
  require 'carrierwave/orm/activerecord'
45
45
  end
46
46
  end
47
+
48
+ ##
49
+ # Loads the Carrierwave locale files before the Rails application locales
50
+ # letting the Rails application overrite the carrierwave locale defaults
51
+ config.before_configuration do
52
+ I18n.load_path << File.join(File.dirname(__FILE__), "carrierwave", "locale", 'en.yml')
53
+ end
47
54
  end
48
55
  end
49
56
 
@@ -46,11 +46,31 @@ module CarrierWave
46
46
  # THE SOFTWARE.
47
47
  #
48
48
  module Paperclip
49
+ extend ActiveSupport::Concern
50
+
51
+ DEFAULT_MAPPINGS = {
52
+ :rails_root => lambda{|u, f| Rails.root.to_s },
53
+ :rails_env => lambda{|u, f| Rails.env },
54
+ :id_partition => lambda{|u, f| ("%09d" % u.model.id).scan(/\d{3}/).join("/")},
55
+ :id => lambda{|u, f| u.model.id },
56
+ :attachment => lambda{|u, f| u.mounted_as.to_s.downcase.pluralize },
57
+ :style => lambda{|u, f| u.paperclip_style },
58
+ :basename => lambda{|u, f| u.filename.gsub(/#{File.extname(u.filename)}$/, "") },
59
+ :extension => lambda{|u, d| File.extname(u.filename).gsub(/^\.+/, "")},
60
+ :class => lambda{|u, f| u.model.class.name.underscore.pluralize}
61
+ }
62
+
63
+ included do
64
+ attr_accessor :filename
65
+ class_attribute :mappings
66
+ self.mappings ||= DEFAULT_MAPPINGS.dup
67
+ end
49
68
 
50
69
  def store_path(for_file=filename)
51
70
  path = paperclip_path
71
+ self.filename = for_file
52
72
  path ||= File.join(*[store_dir, paperclip_style.to_s, for_file].compact)
53
- interpolate_paperclip_path(path, for_file)
73
+ interpolate_paperclip_path(path)
54
74
  end
55
75
 
56
76
  def store_dir
@@ -68,28 +88,18 @@ module CarrierWave
68
88
  version_name || paperclip_default_style
69
89
  end
70
90
 
71
- private
72
-
73
- def interpolate_paperclip_path(path, filename)
74
- mappings.inject(path) do |agg, pair|
75
- agg.gsub(":#{pair[0]}") { pair[1].call(self, filename).to_s }
91
+ module ClassMethods
92
+ def interpolate(sym, &block)
93
+ mappings[sym] = block
76
94
  end
77
95
  end
78
96
 
79
- def mappings
80
- [
81
- [:rails_root , lambda{|u, f| Rails.root }],
82
- [:rails_env , lambda{|u, f| Rails.env }],
83
- [:class , lambda{|u, f| u.model.class.name.underscore.pluralize}],
84
- [:id_partition , lambda{|u, f| ("%09d" % u.model.id).scan(/\d{3}/).join("/")}],
85
- [:id , lambda{|u, f| u.model.id }],
86
- [:attachment , lambda{|u, f| u.mounted_as.to_s.downcase.pluralize }],
87
- [:style , lambda{|u, f| u.paperclip_style }],
88
- [:basename , lambda{|u, f| f.gsub(/#{File.extname(f)}$/, "") }],
89
- [:extension , lambda{|u, f| File.extname(f).gsub(/^\.+/, "")}]
90
- ]
97
+ private
98
+ def interpolate_paperclip_path(path)
99
+ mappings.each_pair.inject(path) do |agg, pair|
100
+ agg.gsub(":#{pair[0]}") { pair[1].call(self, self.paperclip_style).to_s }
101
+ end
91
102
  end
92
-
93
103
  end # Paperclip
94
104
  end # Compatibility
95
105
  end # CarrierWave
@@ -0,0 +1,11 @@
1
+ el:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: "απέτυχε στην επεξεργασία"
5
+ carrierwave_integrity_error: "δεν ανήκει σε επιτρεπτό τύπο αρχείου"
6
+ carrierwave_download_error: "δεν ήταν δυνατό να μεταφορτωθεί"
7
+ extension_white_list_error: "Δεν επιτρέπεται το ανέβασμα αρχείων %{extension}, επιτρεπτοί τύποι: %{allowed_types}"
8
+ extension_black_list_error: "Δεν επιτρέπεται το ανέβασμα αρχείων %{extension}, μη επιτρεπτοί τύποι: %{prohibited_types}"
9
+ rmagick_processing_error: "Απέτυχε ο χειρισμός με rmagick, ίσως δεν είναι εικόνα; Αρχικό Σφάλμα: %{e}"
10
+ mime_types_processing_error: "Απέτυχε η επεξεργασία του αρχείου με MIME::Types, ίσως δεν έχει έγκυρο content-type; Αρχικό Σφάλμα: %{e}"
11
+ mini_magick_processing_error: "Απέτυχε ο χειρισμός με MiniMagick, ίσως δεν είναι εικόνα; Αρχικό Σφάλμα: %{e}"
@@ -0,0 +1,11 @@
1
+ es:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: no se pudo procesar
5
+ carrierwave_integrity_error: no es de un tipo de archivo permitido
6
+ carrierwave_download_error: no se pudo descargar
7
+ extension_white_list_error: "No se pueden subir archivos de esta extensión %{extension}, las extensiones permitidas son: %{allowed_types}"
8
+ extension_black_list_error: "No se pueden subir archivos de esta extensión %{extension}, las extensiones prohibidas son: %{allowed_types}"
9
+ rmagick_processing_error: "No se pudo manipular con rmagick, quizá porque no es una imágen? Error original: %{e}"
10
+ mime_types_processing_error: "No se pudo procesar archivo con MIME::Types, quizá no tiene el content-type correcto? Error original: %{e}"
11
+ mini_magick_processing_error: "No se pudo manipular con MiniMagick, quizá porque no es una imágen? Error original: %{e}"
@@ -0,0 +1,11 @@
1
+ fr:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: "Impossible de redimensionner l'image."
5
+ carrierwave_integrity_error: "Ce n'est pas une image."
6
+ carrierwave_download_error: "Impossible de télécharger l'image."
7
+ extension_white_list_error: "Vous n'êtes pas autorisé à uploader des fichiers %{extension}, types autorisés: %{allowed_types}"
8
+ extension_black_list_error: "Vous n'êtes pas autorisé à uploader des fichiers %{extension}, types interdits: %{prohibited_types}"
9
+ rmagick_processing_error: "La manipulation d'image avec rmagick a échoué. Peut-être que ce n'est pas une image ? Erreur originale: %{e}"
10
+ mime_types_processing_error: "Le traitement de fichier avec MIME::Types a échoué. Peut-être que ce n'est pas un type valide ? Erreur originale: %{e}"
11
+ mini_magick_processing_error: "La manipulation d'image avec MiniMagick a échoué. Peut-être que ce n'est pas une image ? Erreur originale: %{e}"
@@ -0,0 +1,11 @@
1
+ ja:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: 処理できませんでした
5
+ carrierwave_integrity_error: は許可されていないファイルタイプです
6
+ carrierwave_download_error: はダウンロードできません
7
+ extension_white_list_error: "%{extension}ファイルのアップロードは許可されていません。アップロードできるファイルタイプ: %{allowed_types}"
8
+ extension_black_list_error: "%{extension}ファイルのアップロードは許可されていません。アップロードできないファイルタイプ: %{prohibited_types}"
9
+ rmagick_processing_error: "rmagickがファイルを処理できませんでした。画像を確認してください。エラーメッセージ: %{e}"
10
+ mime_types_processing_error: "MIME::Typesのファイルを処理できませんでした。Content-Typeを確認してください。エラーメッセージ: %{e}"
11
+ mini_magick_processing_error: "MiniMagickがファイルを処理できませんでした。画像を確認してください。エラーメッセージ: %{e}"
@@ -0,0 +1,11 @@
1
+ nb:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: kunne ikke behandles
5
+ carrierwave_integrity_error: er ikke en tillatt filtype
6
+ carrierwave_download_error: kunne ikke lastes ned
7
+ extension_white_list_error: "Du kan ikke laste opp %{extension}-filer, tillatte filtyper: %{allowed_types}"
8
+ extension_black_list_error: "Du kan ikke laste opp %{extension}-filer, forbudte filtyper: %{prohibited_types}"
9
+ rmagick_processing_error: "Kunne ikke manipulere med rmagick. Er du sikker på at det er et bilde? Feilmelding: %{e}"
10
+ mime_types_processing_error: "Kunne ikke behandle fil med MIME::Types. Er du sikker på at content-type er korrekt? Feilmelding: %{e}"
11
+ mini_magick_processing_error: "Kunne ikke manipulere med MiniMagick. Er du sikker på at det er et bilde? Feilmelding: %{e}"
@@ -0,0 +1,11 @@
1
+ pl:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: nie można przetworzyć
5
+ carrierwave_integrity_error: niedozwolony typ pliku
6
+ carrierwave_download_error: nie można pobrać pliku
7
+ extension_white_list_error: "Nie można wgrać pliku o rozszerzeniu %{extension}, dozwolone typy plików: %{allowed_types}"
8
+ extension_black_list_error: "Nie można wgrać pliku o rozszerzeniu %{extension}, zakazane typy plików: %{prohibited_types}"
9
+ rmagick_processing_error: "Nie udało się przetworzyć pliku przy pomocy rmagick, może to nie jest obrazek? Oryginalna treść błędu: %{e}"
10
+ mime_types_processing_error: "Nie udało się przetworzyć pliku przy pomocy MIME::Types, może content-type jest niepoprawny? Oryginalna treść błędu: %{e}"
11
+ mini_magick_processing_error: "Nie udało się przetworzyć pliku przy pomocy MiniMagick, może to nie jest obrazek? Oryginalna treść błędu: %{e}"
@@ -0,0 +1,11 @@
1
+ pt-BR:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: falhou em ser processado
5
+ carrierwave_integrity_error: não é um tipo de arquivo permitido
6
+ carrierwave_download_error: não pôde ser baixado
7
+ extension_white_list_error: "Não é permitido o envio de arquivos %{extension}, tipos permitidos: %{allowed_types}"
8
+ extension_black_list_error: "Não é permitido o envio de arquivos %{extension}, tipos proibidos: %{prohibited_types}"
9
+ rmagick_processing_error: "Falha ao manipular com RMagick, talvez arquivo não seja uma imagem? Erro original: %{e}"
10
+ mime_types_processing_error: "Falha ao processar arquivo com MIME::Types, talvez content-type seja inválido? Erro original: %{e}"
11
+ mini_magick_processing_error: "Falha ao manipular com MiniMagick, talvez arquivo não seja uma imagem? Erro original: %{e}"
@@ -0,0 +1,11 @@
1
+ pt-PT:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: falhou ao ser processado
5
+ carrierwave_integrity_error: não é um tipo de ficheiro permitido
6
+ carrierwave_download_error: não pôde ser transferido
7
+ extension_white_list_error: "Não é permitido o envio de ficheiros com a extensão %{extension}, tipos de ficheiro permitidos: %{allowed_types}"
8
+ extension_black_list_error: "Não é permitido o envio de ficheiros com a extensão %{extension}, tipos de ficheiro proibidos: %{prohibited_types}"
9
+ rmagick_processing_error: "Ocorreu uma falha ao processar com rmagick, talvez o ficheiro não seja uma imagem? Erro original: %{e}"
10
+ mime_types_processing_error: "Ocorreu uma falha ao processar com MIME::Types, talvez o parâmetro content-type não seja válido? Erro original: %{e}"
11
+ mini_magick_processing_error: "Ocorreu uma falha ao processar com MiniMagick, talvez o ficheiro não seja uma imagem? Erro original: %{e}"
@@ -0,0 +1,11 @@
1
+ ru:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: Невозможно обработать изображение
5
+ carrierwave_integrity_error: Файл не является изображением
6
+ carrierwave_download_error: Невозможно скачать файл
7
+ extension_white_list_error: "Вы не можете загружать файлы типа %{extension}, разрешенные типы: %{allowed_types}"
8
+ extension_black_list_error: "Вы не можете загружать файлы типа %{extension}, запрещенные типы: %{prohibited_types}"
9
+ rmagick_processing_error: "Ошибка взаимодействия с RMagick, может быть это не изображение? Исходная ошибка: %{e}"
10
+ mime_types_processing_error: "Не получилось обработать файл с MIME::Types, возможно неправильный content-type? Исходная ошибка: %{e}"
11
+ mini_magick_processing_error: "Ошибка взаимодействия с MiniMagick, может быть это не изображение? Исходная ошибка: %{e}"
@@ -0,0 +1,11 @@
1
+ tr:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: işlenmesi sırasında hata oluştu
5
+ carrierwave_integrity_error: izin verilebilir bir dosya türü değil
6
+ carrierwave_download_error: indirilemedi
7
+ extension_white_list_error: "%{extension} uzantılı dosyaları yükleme izniniz yok, izin verilen uzantılar: %{allowed_types}"
8
+ extension_black_list_error: "%{extension} uzantılı dosyaları yükleme izniniz yok, izin verilmeyen uzantılar: %{prohibited_types}"
9
+ rmagick_processing_error: "Resim rmagick ile düzenlenemedi, belkide resim değildir? Orjinal Hata: %{e}"
10
+ mime_types_processing_error: "Dosya, MIME::Types kullanılarak işlenemedi, belkide geçerli bir içerik türü değildir? Orjinal Hata: %{e}"
11
+ mini_magick_processing_error: "Resim MiniMagick ile düzenlenemedi, belkide resim değildir? Orjinal Hata: %{e}"
@@ -20,15 +20,11 @@ module CarrierWave
20
20
  # [Hash{Symbol => CarrierWave}] what uploaders are mounted on which columns
21
21
  #
22
22
  def uploaders
23
- @uploaders ||= {}
24
- @uploaders = superclass.uploaders.merge(@uploaders) if superclass.respond_to?(:uploaders)
25
- @uploaders
23
+ @uploaders ||= superclass.respond_to?(:uploaders) ? superclass.uploaders.dup : {}
26
24
  end
27
25
 
28
26
  def uploader_options
29
- @uploader_options ||= {}
30
- @uploader_options = superclass.uploader_options.merge(@uploader_options) if superclass.respond_to?(:uploader_options)
31
- @uploader_options
27
+ @uploader_options ||= superclass.respond_to?(:uploader_options) ? superclass.uploader_options.dup : {}
32
28
  end
33
29
 
34
30
  ##
@@ -139,24 +135,12 @@ module CarrierWave
139
135
  # end
140
136
  #
141
137
  def mount_uploader(column, uploader=nil, options={}, &block)
142
- if block_given?
143
- uploader = Class.new(uploader || CarrierWave::Uploader::Base)
144
- const_set("Uploader#{uploader.object_id}".gsub('-', '_'), uploader)
145
- uploader.class_eval(&block)
146
- uploader.recursively_apply_block_to_versions(&block)
147
- else
148
- uploader ||= begin
149
- u = Class.new(CarrierWave::Uploader::Base)
150
- const_set("Uploader#{u.object_id}".gsub('-', '_'), u)
151
- u
152
- end
153
- end
138
+ include CarrierWave::Mount::Extension
154
139
 
140
+ uploader = build_uploader(uploader, &block)
155
141
  uploaders[column.to_sym] = uploader
156
142
  uploader_options[column.to_sym] = options
157
143
 
158
- include CarrierWave::Mount::Extension
159
-
160
144
  # Make sure to write over accessors directly defined on the class.
161
145
  # Simply super to the included module below.
162
146
  class_eval <<-RUBY, __FILE__, __LINE__+1
@@ -180,7 +164,7 @@ module CarrierWave
180
164
  end
181
165
 
182
166
  def #{column}?
183
- !_mounter(:#{column}).blank?
167
+ _mounter(:#{column}).present?
184
168
  end
185
169
 
186
170
  def #{column}_url(*args)
@@ -262,9 +246,29 @@ module CarrierWave
262
246
  end
263
247
  end
264
248
 
249
+ def mark_remove_#{column}_false
250
+ _mounter(:#{column}).remove = false
251
+ end
252
+
265
253
  RUBY
266
254
  end
267
255
 
256
+ private
257
+
258
+ def build_uploader(uploader, &block)
259
+ return uploader if uploader && !block_given?
260
+
261
+ uploader = Class.new(uploader || CarrierWave::Uploader::Base)
262
+ const_set("Uploader#{uploader.object_id}".gsub('-', '_'), uploader)
263
+
264
+ if block_given?
265
+ uploader.class_eval(&block)
266
+ uploader.recursively_apply_block_to_versions(&block)
267
+ end
268
+
269
+ uploader
270
+ end
271
+
268
272
  module Extension
269
273
 
270
274
  ##
@@ -304,8 +308,8 @@ module CarrierWave
304
308
  return if record.frozen?
305
309
 
306
310
  if remove?
307
- record.write_uploader(serialization_column, '')
308
- elsif not uploader.identifier.blank?
311
+ record.write_uploader(serialization_column, nil)
312
+ elsif uploader.identifier.present?
309
313
  record.write_uploader(serialization_column, uploader.identifier)
310
314
  end
311
315
  end
@@ -316,11 +320,9 @@ module CarrierWave
316
320
 
317
321
  def uploader
318
322
  @uploader ||= record.class.uploaders[column].new(record, column)
323
+ @uploader.retrieve_from_store!(identifier) if @uploader.blank? && identifier.present?
319
324
 
320
- if @uploader.blank? and not identifier.blank?
321
- @uploader.retrieve_from_store!(identifier)
322
- end
323
- return @uploader
325
+ @uploader
324
326
  end
325
327
 
326
328
  def cache(new_file)
@@ -345,10 +347,11 @@ module CarrierWave
345
347
  end
346
348
 
347
349
  def remote_url=(url)
348
- @download_error = nil
349
- @integrity_error = nil
350
+ return if url.blank?
350
351
 
351
352
  @remote_url = url
353
+ @download_error = nil
354
+ @integrity_error = nil
352
355
 
353
356
  uploader.download!(url)
354
357
 
@@ -364,12 +367,12 @@ module CarrierWave
364
367
  end
365
368
 
366
369
  def store!
367
- unless uploader.blank?
368
- if remove?
369
- uploader.remove!
370
- else
371
- uploader.store!
372
- end
370
+ return if uploader.blank?
371
+
372
+ if remove?
373
+ uploader.remove!
374
+ else
375
+ uploader.store!
373
376
  end
374
377
  end
375
378
 
@@ -382,7 +385,7 @@ module CarrierWave
382
385
  end
383
386
 
384
387
  def remove?
385
- !remove.blank? and remove !~ /\A0|false$\z/
388
+ remove.present? && remove !~ /\A0|false$\z/
386
389
  end
387
390
 
388
391
  def remove!