vendor/plugins/rust-file_column/lib/validations.rb
# This validates the file type of one or more file_columns.  A list of file columns
# should be given followed by an options hash.
#
# Required options:
# * <tt>:in</tt> => list of extensions or mime types. If mime types are used they
#   will be mapped into an extension via FileColumn::ClassMethods::MIME_EXTENSIONS.
#
# Examples:
#     validates_file_format_of :field, :in => ["gif", "png", "jpg"]
#     validates_file_format_of :field, :in => ["image/jpeg"]
This validates the file type of one or more file_columns.  A list of file columns
should be given followed by an options hash.

Required options:
:in => list of extensions or mime types. If mime types are used they
will be mapped into an extension via FileColumn::ClassMethods::MIME_EXTENSIONS.


This validates the file type of one or more file_columns . A list of file columns should be given followed by an options hash . Required options : : in = > list of extensions or mime types . If mime types are used they will be mapped into an extension via FileColumn :: ClassMethods :: MIME_EXTENSIONS .
def validates_file_format_of(*attrs)
        options = attrs.pop if attrs.last.is_a?Hash
        raise ArgumentError, "Please include the :in option." if !options || !options[:in]
        options[:in] = [options[:in]] if options[:in].is_a?String
        raise ArgumentError, "Invalid value for option :in" unless options[:in].is_a?Array
        validates_each(attrs, options) do |record, attr, value|
          unless value.blank?
            mime_extensions = record.send("#{attr}_options")[:mime_extensions]
            extensions = options[:in].map{|o| mime_extensions[o] || o }
            record.errors.add attr, "is not a valid format." unless extensions.include?(value.scan(EXT_REGEXP).flatten.first)
          end
        end
      end
def validates_file_format_of ( * attrs ) options = attrs . pop if attrs . last . is_a? Hash raise ArgumentError , "Please include the :in option." if ! options || ! options [ :in ] options [ :in ] = [ options [ :in ] ] if options [ :in ] . is_a? String raise ArgumentError , "Invalid value for option :in" unless options [ :in ] . is_a? Array validates_each ( attrs , options ) do | record , attr , value | unless value . blank? mime_extensions = record . send ( "#{attr}_options" ) [ :mime_extensions ] extensions = options [ :in ] . map { | o | mime_extensions [ o ] || o } record . errors . add attr , "is not a valid format." unless extensions . include? ( value . scan ( EXT_REGEXP ) . flatten . first ) end end end
This validates the file type of one or more file_columns.
This validates the file type of one or more file_columns .
attrs
<not_specific>