Class: Sanitized::String

Inherits:
ActiveModel::Type::String
  • Object
show all
Includes:
Base
Defined in:
lib/sanitized/string.rb

Overview

Description

ActiveModel::Type to cast and sanitize a model’s String attribute according to the options specified on initialisation.

attribute :attr_name, Sanitized::String.new(:squish, :upcase), default: ‘CodeMeister’

Can optionally include a custom block:

type_cast = Sanitized::String.new(:squish, :upcase) do |value|
    ... custome code ...
end
attribute :attr_name, type_cast, default: 'CodeMeister'

Class Method Summary collapse

Methods included from Base

#cast, #options

Class Method Details

.valid_optionsObject

Returns a Hash of valid options with the other options they are exclusive with



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sanitized/string.rb', line 36

def self.valid_options
  case_opts = [:capitalize, :camelcase, :camelize, :dasherize, :downcase, :humanize,
               :parameterize, :swapcase, :titlecase, :titleize, :underscore, :upcase,
               :upcase_first]
  {
    capitalize:   case_opts,
    camelcase:    case_opts,
    camelize:     case_opts,
    chomp:        [],
    dasherize:    case_opts,
    downcase:     case_opts,
    humanize:     case_opts,
    lstrip:       [],
    parameterize: case_opts,
    rstrip:       [],
    singularize:  [],
    squish:       [],
    strip:        [],
    swapcase:     case_opts,
    titlecase:    case_opts,
    titleize:     case_opts,
    underscore:   case_opts,
    upcase:       case_opts,
    upcase_first: case_opts
  }
end