Sha256: 301f5dd7501f4126b82ed4b6d455bc97066b2cf30f645bee96c5a05f19dfa726

Contents?: true

Size: 1.51 KB

Versions: 62

Compression:

Stored size: 1.51 KB

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. Compares the file's extension case insensitive.
      # Furthermore, not only strings but Regexp are allowed as well.
      #
      # When using a Regexp in the white list, `\A` and `\z` are automatically added to
      # the Regexp expression, also case insensitive.
      #
      # === Returns
      #
      # [NilClass, Array[String,Regexp]] a white list of extensions which are allowed to be uploaded
      #
      # === Examples
      #
      #     def extension_white_list
      #       %w(jpg jpeg gif png)
      #     end
      #
      # Basically the same, but using a Regexp:
      #
      #     def extension_white_list
      #       [/jpe?g/, 'gif', 'png']
      #     end
      #
      def extension_white_list; end

    private

      def check_whitelist!(new_file)
        extension = new_file.extension.to_s
        if extension_white_list and not extension_white_list.detect { |item| extension =~ /\A#{item}\z/i }
          raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_white_list_error", :extension => new_file.extension.inspect, :allowed_types => extension_white_list.inspect)
        end
      end

    end # ExtensionWhitelist
  end # Uploader
end # CarrierWave

Version data entries

62 entries across 57 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.7.4 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.7.3 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.7.2 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.7.1 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.7.0 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.9 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-pressplane-0.5.8.3 lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.8 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.7 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.6 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.5 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.4 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.3 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.2 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.1 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.6.0 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.5.17 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.5.16 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb
classiccms-0.5.15 vendor/bundle/gems/carrierwave-0.6.2/lib/carrierwave/uploader/extension_whitelist.rb