Class: Mongory::Converters::DataConverter

Inherits:
AbstractConverter show all
Defined in:
lib/mongory/converters/data_converter.rb

Overview

DataConverter handles automatic transformation of raw query values. This class inherits from AbstractConverter and provides predefined conversions for common primitive types like Symbol, Date, Time, etc.

  • Symbols and Date objects are converted to string
  • Time and DateTime objects are ISO8601-encoded
  • Strings and Integers are passed through as-is

Examples:

Convert a symbol

DataConverter.instance.convert(:status) #=> "status"

Constant Summary

Constants inherited from AbstractConverter

AbstractConverter::NOTHING

Instance Method Summary collapse

Methods inherited from AbstractConverter

#configure, #fallback, #find_strategy, #freeze, #initialize, #register

Methods inherited from Utils::SingletonBuilder

#initialize, #inspect, #to_s

Constructor Details

This class inherits a constructor from Mongory::Converters::AbstractConverter

Instance Method Details

#convert(target) ⇒ Object

Converts a value into its standardized form based on its type. Handles common primitive types with predefined conversion rules.

Parameters:

  • target (Object)

    the value to convert

Returns:

  • (Object)

    the converted value



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mongory/converters/data_converter.rb', line 23

def convert(target)
  case target
  when String, Integer, Hash, Array
    target
  when Symbol, Date
    target.to_s
  when Time, DateTime
    target.iso8601
  else
    super_convert(target)
  end
end

#super_convertObject



16
# File 'lib/mongory/converters/data_converter.rb', line 16

alias_method :super_convert, :convert