Class: Typero::ImageType

Inherits:
Type
  • Object
show all
Defined in:
lib/typero/type/types/image_type.rb

Constant Summary collapse

FORMATS =
%w[jpg jpeg gif png svg webp]

Constants inherited from Type

Type::ERRORS, Type::OPTS, Type::OPTS_KEYS

Instance Attribute Summary

Attributes inherited from Type

#opts

Instance Method Summary collapse

Methods inherited from Type

allowed_opt?, #db_field, db_schema, #default, error, #get, #initialize, load, opts, #value

Constructor Details

This class inherits a constructor from Typero::Type

Instance Method Details

#db_schemaObject



20
21
22
# File 'lib/typero/type/types/image_type.rb', line 20

def db_schema
  [:string]
end

#setObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/typero/type/types/image_type.rb', line 9

def set
  error_for(:image_not_starting_error) unless value =~ /^https?:\/\/./

  if opts[:strict]
    # strip query string and fragment before checking extension
    path = value.split('?').first.split('#').first
    ext = path.split('.').last.downcase
    error_for(:image_not_image_format) unless FORMATS.include?(ext)
  end
end