module

Latch::Avram::Validations

File attachment validations for Avram SaveOperations.

Included automatically via Latch::Avram::SaveOperation.

Instance methods

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
Source
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
Source
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
Source