Class: Mongory::Converters::ConditionConverter
- Inherits:
-
AbstractConverter
- Object
- Utils::SingletonBuilder
- AbstractConverter
- Mongory::Converters::ConditionConverter
- Defined in:
- lib/mongory/converters/condition_converter.rb
Overview
ConditionConverter transforms a flat condition hash into nested hash form. This is used internally by ValueConverter to normalize condition structures like { "foo.bar" => 1, "foo.baz" => 2 } into nested Mongo-style conditions. Used by QueryMatcher to normalize condition input for internal matching.
Combines key transformation (via KeyConverter) and value normalization (via ValueConverter), and merges overlapping keys.
Constant Summary
Constants inherited from AbstractConverter
Instance Method Summary collapse
-
#convert(condition) ⇒ Hash
Converts a flat condition hash into a nested structure.
-
#freeze ⇒ void
Freezes internal converters to prevent further modification.
-
#key_converter ⇒ AbstractConverter
Returns the key converter used to transform condition keys.
-
#value_converter ⇒ AbstractConverter
Returns the value converter used to transform condition values.
Methods inherited from AbstractConverter
#configure, #fallback, #find_strategy, #initialize, #register
Methods inherited from Utils::SingletonBuilder
Constructor Details
This class inherits a constructor from Mongory::Converters::AbstractConverter
Instance Method Details
#convert(condition) ⇒ Hash
Converts a flat condition hash into a nested structure. Applies both key and value conversion, and merges overlapping keys.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongory/converters/condition_converter.rb', line 23 def convert(condition) return condition if condition.is_a?(Converted) result = Converted::Hash.new condition.each_pair do |k, v| converted_value = value_converter.convert(v) converted_pair = key_converter.convert(k, converted_value) result.deep_merge!(converted_pair) end result end |
#freeze ⇒ void
This method returns an undefined value.
Freezes internal converters to prevent further modification.
55 56 57 58 59 |
# File 'lib/mongory/converters/condition_converter.rb', line 55 def freeze super key_converter.freeze value_converter.freeze end |
#key_converter ⇒ AbstractConverter
Singleton instance, not configurable after initialization
Returns the key converter used to transform condition keys.
40 41 42 |
# File 'lib/mongory/converters/condition_converter.rb', line 40 def key_converter KeyConverter.instance end |
#value_converter ⇒ AbstractConverter
Singleton instance, not configurable after initialization
Returns the value converter used to transform condition values.
48 49 50 |
# File 'lib/mongory/converters/condition_converter.rb', line 48 def value_converter ValueConverter.instance end |