Class: MiniDefender::Rules::Image
Constant Summary
collapse
- MIMES =
%w[image/jpeg image/png image/gif image/bmp image/png image/svg+xml image/webp]
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message
Class Method Details
.signature ⇒ Object
9
10
11
|
# File 'lib/mini_defender/rules/image.rb', line 9
def self.signature
'image'
end
|
Instance Method Details
#message(attribute, value, validator) ⇒ Object
20
21
22
|
# File 'lib/mini_defender/rules/image.rb', line 20
def message(attribute, value, validator)
"The field should be an image of type jpg, jpeg, png, bmp, gif, svg, or webp."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
13
14
15
16
17
18
|
# File 'lib/mini_defender/rules/image.rb', line 13
def passes?(attribute, value, validator)
content_type = Marcel::MimeType.for(value.read)
value.rewind
value.is_a?(ActionDispatch::Http::UploadedFile) && MIMES.include?(content_type)
end
|