Class: Mongory::Converters::ValueConverter
- Inherits:
-
AbstractConverter
- Object
- Utils::SingletonBuilder
- AbstractConverter
- Mongory::Converters::ValueConverter
- Defined in:
- lib/mongory/converters/value_converter.rb
Overview
ValueConverter transforms query values into a standardized form. It handles arrays, hashes, regex, and basic types, and delegates fallback logic to DataConverter. Used by ConditionConverter to prepare values in nested queries.
- Arrays are recursively converted
- Hashes are interpreted as nested conditions
- Regex becomes a Mongo-style
$regex
hash - Strings and Integers are passed through
- Everything else falls back to DataConverter
Constant Summary
Constants inherited from AbstractConverter
Instance Method Summary collapse
-
#condition_converter ⇒ ConditionConverter
Returns the condition converter instance.
-
#convert(target) ⇒ Object
Converts a value into its standardized form based on its type.
- #fallback(target) ⇒ Object
- #super_convert ⇒ Object
Methods inherited from AbstractConverter
#configure, #find_strategy, #freeze, #initialize, #register
Methods inherited from Utils::SingletonBuilder
Constructor Details
This class inherits a constructor from Mongory::Converters::AbstractConverter
Instance Method Details
#condition_converter ⇒ ConditionConverter
Returns the condition converter instance.
47 48 49 |
# File 'lib/mongory/converters/value_converter.rb', line 47 def condition_converter @condition_converter ||= Mongory.condition_converter end |
#convert(target) ⇒ Object
Converts a value into its standardized form based on its type. Handles arrays, hashes, regex, and basic types.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongory/converters/value_converter.rb', line 27 def convert(target) case target when String, Integer, Regexp, Converted target when Array Converted::Array.new(target.map { |x| convert(x) }) when Hash condition_converter.convert(target) else super_convert(target) end end |
#fallback(target) ⇒ Object
40 41 42 |
# File 'lib/mongory/converters/value_converter.rb', line 40 def fallback(target, *) Mongory.data_converter.convert(target) end |
#super_convert ⇒ Object
20 |
# File 'lib/mongory/converters/value_converter.rb', line 20 alias_method :super_convert, :convert |