Module: CMDx::Coercions::Array
Overview
Converts various input types to Array format
Handles conversion from strings that look like JSON arrays and other values that can be wrapped in an array using Ruby’s Array() method.
Instance Method Summary collapse
-
#call(value, options = EMPTY_HASH) ⇒ Array
Converts a value to an Array.
Instance Method Details
#call(value, options = EMPTY_HASH) ⇒ Array
Converts a value to an Array
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cmdx/coercions/array.rb', line 33 def call(value, = EMPTY_HASH) if value.is_a?(::String) && ( value.start_with?("[") || value.strip == "null" ) JSON.parse(value) || [] else Utils::Wrap.array(value) end rescue JSON::ParserError type = Locale.t("cmdx.types.array") raise CoercionError, Locale.t("cmdx.coercions.into_an", type:) end |