Module: Carrierwave::Base64::MountingHelper
- Defined in:
- lib/carrierwave/base64/mounting_helper.rb
Overview
Module with helper functions for mounting uploaders
Class Method Summary collapse
-
.check_for_deprecations(options) ⇒ void
Checks for deprecations and prints a warning if found any.
-
.define_writer(klass, attr, options) ⇒ Symbol
Defines an attribute writer method on the class with mounted uploader.
-
.file_name(model_instance, options) ⇒ String
Returns a file name for the uploaded file.
Class Method Details
.check_for_deprecations(options) ⇒ void
This method returns an undefined value.
Checks for deprecations and prints a warning if found any.
12 13 14 15 16 17 18 19 20 |
# File 'lib/carrierwave/base64/mounting_helper.rb', line 12 def check_for_deprecations() return unless [:file_name].is_a?(String) warn( '[Deprecation warning] Setting `file_name` option to a string is '\ 'deprecated and will be removed in 3.0.0. If you want to keep the '\ 'existing behaviour, wrap the string in a Proc' ) end |
.define_writer(klass, attr, options) ⇒ Symbol
Defines an attribute writer method on the class with mounted uploader.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/carrierwave/base64/mounting_helper.rb', line 43 def define_writer(klass, attr, ) klass.send(:define_method, "#{attr}=") do |data| # rubocop:disable Lint/NonLocalExitFromIterator return if data == send(attr).to_s # rubocop:enable Lint/NonLocalExitFromIterator send("#{attr}_will_change!") if respond_to?("#{attr}_will_change!") return send("remove_#{attr}=", true) if data.to_s.strip == '' return super(data) unless data.is_a?(String) && data.strip.start_with?('data') super Carrierwave::Base64::Base64StringIO.new( data.strip, Carrierwave::Base64::MountingHelper.file_name(self, ) ) end end |
.file_name(model_instance, options) ⇒ String
Returns a file name for the uploaded file.
28 29 30 31 32 33 34 |
# File 'lib/carrierwave/base64/mounting_helper.rb', line 28 def file_name(model_instance, ) if [:file_name].respond_to?(:call) [:file_name].call(model_instance) else [:file_name] end.to_s end |