Sha256: 415005ddf6018f533ce09060ee41e869a10c9525aacf86e665b1ef86b23d71ed

Contents?: true

Size: 1021 Bytes

Versions: 9

Compression:

Stored size: 1021 Bytes

Contents

# encoding: utf-8

module CarrierWave
  module Uploader
    module ExtensionWhitelist
      extend ActiveSupport::Concern

      included do
        before :cache, :check_whitelist!
      end

      ##
      # Override this method in your uploader to provide a white list of extensions which
      # are allowed to be uploaded.
      #
      # === Returns
      #
      # [NilClass, Array[String]] a white list of extensions which are allowed to be uploaded
      #
      # === Examples
      #
      #     def extension_white_list
      #       %w(jpg jpeg gif png)
      #     end
      #
      def extension_white_list; end

    private

      def check_whitelist!(new_file)
        if extension_white_list and not extension_white_list.include?(new_file.extension.to_s)
          raise CarrierWave::IntegrityError, "You are not allowed to upload #{new_file.extension.inspect} files, allowed types: #{extension_white_list.inspect}"
        end
      end

    end # ExtensionWhitelist
  end # Uploader
end # CarrierWave

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
locomotive_carrierwave-0.5.0.1.beta3 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.5.1 lib/carrierwave/uploader/extension_whitelist.rb
locomotive_carrierwave-0.5.0.1.beta2 lib/carrierwave/uploader/extension_whitelist.rb
locomotive_carrierwave-0.5.0.1.beta1 lib/carrierwave/uploader/extension_whitelist.rb
locomotive_carrierwave-0.5.0.1 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.5.0 lib/carrierwave/uploader/extension_whitelist.rb
jswanner-carrierwave-0.5.0.beta3 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.5.0.beta2 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-rails3-0.4.5 lib/carrierwave/uploader/extension_whitelist.rb