ActiveModel::EachValidator
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 35 def allowed_types [options[:content_type]].flatten.compact end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 43 def check_validity! unless options.has_key?(:content_type) || options.has_key?(:not) raise ArgumentError, "You must pass in either :content_type or :not to the validator" end end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 39 def forbidden_types [options[:not]].flatten.compact end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 31 def mark_invalid(record, attribute, types) record.errors.add attribute, :invalid, options.merge(:types => types.join(', ')) end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 25 def validate_blacklist(record, attribute, value) if forbidden_types.present? && forbidden_types.any? { |type| type === value } mark_invalid record, attribute, forbidden_types end end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 9 def validate_each(record, attribute, value) attribute = "#{attribute}_content_type".to_sym value = record.send :read_attribute_for_validation, attribute return if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank]) validate_whitelist(record, attribute, value) validate_blacklist(record, attribute, value) end
# File lib/paperclip/validators/attachment_content_type_validator.rb, line 19 def validate_whitelist(record, attribute, value) if allowed_types.present? && allowed_types.none? { |type| type === value } mark_invalid record, attribute, allowed_types end end
Generated with the Darkfish Rdoc Generator 2.