Module: CMDx::Coercions::Symbol
Overview
Coerces values to Symbol type using Ruby’s to_sym method.
This coercion handles various input types by converting them to symbols. It provides error handling for values that cannot be converted to symbols and raises appropriate CMDx coercion errors with localized messages.
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ Symbol
Coerces a value to Symbol type.
Instance Method Details
#call(value, options = {}) ⇒ Symbol
Coerces a value to Symbol type.
31 32 33 34 35 36 |
# File 'lib/cmdx/coercions/symbol.rb', line 31 def call(value, = {}) value.to_sym rescue NoMethodError type = Locale.t("cmdx.types.symbol") raise CoercionError, Locale.t("cmdx.coercions.into_a", type:) end |