Class: Decidim::Cw::ApplicationUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- Decidim::Cw::ApplicationUploader
- Includes:
- CarrierWave::MiniMagick
- Defined in:
- app/uploaders/decidim/cw/application_uploader.rb
Overview
This class deals with uploading files to Decidim. It is intended to just hold the uploads configuration, so you should inherit from this class and then tweak any configuration you need.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#validable_dimensions ⇒ Object
readonly
Returns the value of attribute validable_dimensions.
Class Method Summary collapse
- .set_variants ⇒ Object
-
.variants ⇒ Object
Each class inherits variants from parents and can define their own variants with the set_variants class method which calss the version CarrierWave macro to define versions from variants.
Instance Method Summary collapse
-
#downloader ⇒ Object
We overwrite the downloader to be able to fetch some elements from URL.
-
#provider ⇒ Object
As of Carrierwave 2.0 fog_provider method has been deprecated, and is throwing RuntimeError RuntimeError: Carrierwave fog_provider not supported: DEPRECATION WARNING: #fog_provider is deprecated…
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
- #variant(key) ⇒ Object
Instance Attribute Details
#validable_dimensions ⇒ Object (readonly)
Returns the value of attribute validable_dimensions.
9 10 11 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 9 def validable_dimensions @validable_dimensions end |
Class Method Details
.set_variants ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 64 def set_variants return unless block_given? variants.merge!(yield) variants.each do |key, value| version key, if: :image? do process value end end end |
.variants ⇒ Object
Each class inherits variants from parents and can define their own variants with the set_variants class method which calss the version CarrierWave macro to define versions from variants
60 61 62 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 60 def variants @variants ||= superclass.respond_to?(:variants) ? superclass.variants.dup : {} end |
Instance Method Details
#downloader ⇒ Object
We overwrite the downloader to be able to fetch some elements from URL.
31 32 33 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 31 def downloader Decidim::Downloader end |
#provider ⇒ Object
As of Carrierwave 2.0 fog_provider method has been deprecated, and is throwing RuntimeError RuntimeError: Carrierwave fog_provider not supported: DEPRECATION WARNING: #fog_provider is deprecated… We are attempting to fetch the provider from credentials, if not we consider to be file
26 27 28 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 26 def provider fog_credentials.fetch(:provider, "file").downcase end |
#store_dir ⇒ Object
Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:
15 16 17 18 19 20 21 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 15 def store_dir default_path = "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" return File.join(Decidim.base_uploads_path, default_path) if Decidim.base_uploads_path.present? default_path end |
#variant(key) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/uploaders/decidim/cw/application_uploader.rb', line 35 def variant(key) if key && variants[key].present? model.send(mounted_as).variant(variants[key]) else model.send(mounted_as) end end |