Class: FroalaEditorSDK::Validation
- Inherits:
-
Object
- Object
- FroalaEditorSDK::Validation
- Defined in:
- lib/froala-editor-sdk/utils/validation.rb
Overview
Image Validation class. Checks if image is matching the allowed extensions and mime types.
Class Method Summary collapse
-
.check(file, options = nil) ⇒ Object
Checks an image with the options.
- .ext(ext, options) ⇒ Object
- .mime(mime, options) ⇒ Object
Class Method Details
.check(file, options = nil) ⇒ Object
Checks an image with the options. Params:
file-
The image that will be validated.
options-
The image options that contain allowed extensions and mime types.
Raises exception if the image has not passed the validation
21 22 23 24 25 26 27 |
# File 'lib/froala-editor-sdk/utils/validation.rb', line 21 def self.check(file, = nil) mime = file.content_type ext = ::File.extname(file.original_filename) if ext(ext, ) && mime(mime, ) end end |
.ext(ext, options) ⇒ Object
8 9 10 |
# File 'lib/froala-editor-sdk/utils/validation.rb', line 8 def self.ext(ext, ) raise "Not allowed" unless [:validation][:allowedExts].include?(ext) end |
.mime(mime, options) ⇒ Object
12 13 14 |
# File 'lib/froala-editor-sdk/utils/validation.rb', line 12 def self.mime(mime, ) raise "Invalid mime type" unless [:validation][:allowedMimeTypes].include?(mime) end |