Class: Sekisyo::Validators::FileValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/sekisyo/validators/file_validator.rb

Overview

Sekisyo Validators FileValidator is a validator that accepts only file params value.

Constant Summary collapse

FILE_CONTENT_TYPES =
%w[
  text/plain
  text/csv
  text/html
  text/css
  text/javascript
  application/octet-stream
  application/json
  application/pdf
  application/vnd.ms-excel
  application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  application/vnd.ms-powerpoint
  application/vnd.openxmlformats-officedocument.presentationml.presentation
  application/msword
  application/vnd.openxmlformats-officedocument.wordprocessingml.document
  image/jpeg
  image/png
  image/gif
  image/bmp
  image/svg+xml
  application/zip
  application/x-lzh
  application/x-tar
  audio/mpeg
  video/mp4
  video/mpeg
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, options = {}) ⇒ FileValidator

Returns a new instance of FileValidator.



37
38
39
40
# File 'lib/sekisyo/validators/file_validator.rb', line 37

def initialize(key, options = {})
  @key = key
  @options = options
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



42
43
44
# File 'lib/sekisyo/validators/file_validator.rb', line 42

def key
  @key
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/sekisyo/validators/file_validator.rb', line 44

def valid?(value)
  type_validate(value) &&
    presence_validate(value) &&
    file_size_validate(value)
end