module
Latch::Avram::Validations
Overview
File attachment validations for Avram SaveOperations.
Included automatically via Latch::Avram::SaveOperation.
Direct including types
Defined in:
latch/avram/validations.crInstance Method Summary
-
#validate_file_mime_type_of(attribute, in allowed : Enumerable(String), message : String = "is not an accepted file type", allow_blank : Bool = false) : Bool
Validates that the file has one of the allowed MIME types.
-
#validate_file_mime_type_of(attribute, with pattern : Regex, message : String = "is not an accepted file type", allow_blank : Bool = false) : Bool
Validates that the file MIME type matches the given pattern.
-
#validate_file_size_of(attribute, min : Int64 = 0_i64, max : Int64 | Nil = nil, message : String | Nil = nil, allow_blank : Bool = false) : Bool
Validates that the file size is within the given bounds.
Instance Method Detail
def validate_file_mime_type_of(attribute, in allowed : Enumerable(String), message : String = "is not an accepted file type", allow_blank : Bool = false) : Bool
#
Validates that the file has one of the allowed MIME types.
before_save do
validate_file_mime_type_of avatar_file, in: %w[image/png image/jpeg]
end
def validate_file_mime_type_of(attribute, with pattern : Regex, message : String = "is not an accepted file type", allow_blank : Bool = false) : Bool
#
Validates that the file MIME type matches the given pattern.
before_save do
validate_file_mime_type_of avatar_file, with: /image\/.*/
end
def validate_file_size_of(attribute, min : Int64 = 0_i64, max : Int64 | Nil = nil, message : String | Nil = nil, allow_blank : Bool = false) : Bool
#
Validates that the file size is within the given bounds.
before_save do
validate_file_size_of avatar_file, max: 5_000_000
validate_file_size_of avatar_file, min: 1_000, max: 5_000_000
end