Class: HashCast::Casters::SymbolCaster
- Inherits:
-
Object
- Object
- HashCast::Casters::SymbolCaster
- Defined in:
- lib/hash_cast/casters/symbol_caster.rb
Constant Summary collapse
- MAX_SYMBOL_LENGTH =
1000
Class Method Summary collapse
Class Method Details
.cast(value, attr_name, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hash_cast/casters/symbol_caster.rb', line 4 def self.cast(value, attr_name, = {}) if value.is_a?(Symbol) value elsif value.is_a?(String) if value.length > MAX_SYMBOL_LENGTH raise HashCast::Errors::CastingError, "is too long to be a symbol" else value.to_sym end else raise HashCast::Errors::CastingError, "should be a symbol" end end |