Sha256: 7f5fa9a5835b234f732e7231de38eb662398b4baaa246c3e8690f56b0d830c8d

Contents?: true

Size: 981 Bytes

Versions: 36

Compression:

Stored size: 981 Bytes

Contents

# encoding: utf-8

module CarrierWave
  module Uploader
    module ExtensionWhitelist

      setup 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

36 entries across 36 versions & 7 rubygems

Version Path
andrewtimberlake-carrierwave-0.3.2.1 lib/carrierwave/uploader/extension_whitelist.rb
durran-carrierwave-0.3.2.3 lib/carrierwave/uploader/extension_whitelist.rb
jnicklas-carrierwave-0.3.2.1 lib/carrierwave/uploader/extension_whitelist.rb
jnicklas-carrierwave-0.3.2 lib/carrierwave/uploader/extension_whitelist.rb
jnicklas-carrierwave-0.3.3 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.12 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.11 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.10 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.9 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.8 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.6 lib/carrierwave/uploader/extension_whitelist.rb
thorsson_carrierwave-0.4.5 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.4.10 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.4.9 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.4.8 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.4.7 lib/carrierwave/uploader/extension_whitelist.rb
carrierwave-0.4.6 lib/carrierwave/uploader/extension_whitelist.rb
samlown-carrierwave-0.4.5 lib/carrierwave/uploader/extension_whitelist.rb
dsturnbull-carrierwave-0.4.9 lib/carrierwave/uploader/extension_whitelist.rb
dsturnbull-carrierwave-0.4.8 lib/carrierwave/uploader/extension_whitelist.rb