Sha256: 40a1d7dcc261814370b057baf14522bc54a79fd1a761b10341b27b1fbd18c7b1

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module Carrierwave
  module Base64
    # Module with .mount_base64_uploader method, that is mixed in to
    # ActiveRecord::Base or Mongoid::Document::ClassMethods
    module Adapter
      # Mounts the carrierwave uploader that can accept a base64 encoded
      # string as input. It also accepts regular file uploads.
      #
      # @param attribute [Symbol] the attribute to mount this uploader on
      # @param uploader_class [Carrierwave::Uploader] the uploader class to
      #   mount
      # @param options [Hash{Symbol => Object}] a set of options
      # @option options [Proc] :file_name Proc that must return a file name
      #   without extension
      #
      # @example Mount the uploader and specify the file name
      #   mount_base64_uploader :image, ImageUploader,
      #     file_name: -> (u) { u.username }
      #
      # @example Mount the uploader with a block, overriding the store_dir
      #   mount_base64_uploader :image, ImageUploader do
      #     def store_dir
      #       'images'
      #     end
      #   end
      #
      # @return [Symbol] the defined writer method name
      def mount_base64_uploader(attribute, uploader_class, options = {}, &block)
        mount_uploader attribute, uploader_class, options, &block
        options[:file_name] ||= proc { attribute }

        Carrierwave::Base64::MountingHelper.check_for_deprecations(options)

        Carrierwave::Base64::MountingHelper.define_writer(
          self, attribute, options
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carrierwave-base64-2.11.0 lib/carrierwave/base64/adapter.rb
carrierwave-base64-2.10.0 lib/carrierwave/base64/adapter.rb