Class: Typero::StringType

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

Direct Known Subclasses

TextType

Constant Summary

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



17
18
19
20
21
# File 'lib/typero/type/types/string_type.rb', line 17

def db_schema
  [:string, {
    limit: @opts[:max] || 255
  }]
end

#setObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/typero/type/types/string_type.rb', line 6

def set
  value(&:to_s)
  value(&:downcase) if opts[:downcase]

  # this is database default for string type and it is good to define default unless defined
  opts[:max] ||= 255

  error_for(:min_length_error, opts[:min], value.length) if opts[:min] && value.length < opts[:min]
  error_for(:max_length_error, opts[:max], value.length) if opts[:max] && value.length > opts[:max]
end