Class: Rbdantic::Validators::Types::Symbol

Inherits:
Base
  • Object
show all
Defined in:
lib/rbdantic/validators/types/symbol.rb

Constant Summary collapse

MAX_SYMBOL_LENGTH =
256

Instance Attribute Summary

Attributes inherited from Base

#constraints

Instance Method Summary collapse

Methods inherited from Base

#initialize, #validate, #validate_constraints

Constructor Details

This class inherits a constructor from Rbdantic::Validators::Types::Base

Instance Method Details

#coerce(value) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rbdantic/validators/types/symbol.rb', line 19

def coerce(value)
  case value
  when ::Symbol then value
  when ::String
    value.to_sym if !value.empty? && value.length <= MAX_SYMBOL_LENGTH
  else nil
  end
end

#expected_type_nameObject



15
16
17
# File 'lib/rbdantic/validators/types/symbol.rb', line 15

def expected_type_name
  "Symbol"
end

#matches_type?(value) ⇒ Boolean



11
12
13
# File 'lib/rbdantic/validators/types/symbol.rb', line 11

def matches_type?(value)
  value.is_a?(::Symbol)
end