Class: FroalaEditorSDK::Validation

Inherits:
Object
  • Object
show all
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

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, options = nil)

  mime = file.content_type
  ext = ::File.extname(file.original_filename)
  if ext(ext, options) && mime(mime, options)
  end
end

.ext(ext, options) ⇒ Object



8
9
10
# File 'lib/froala-editor-sdk/utils/validation.rb', line 8

def self.ext(ext, options)
  raise "Not allowed" unless options[: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, options)
  raise "Invalid mime type" unless options[:validation][:allowedMimeTypes].include?(mime)
end