module Aliyun::Log::Record::TypeCasting
Constants
- TYPE_MAPPING
Public Class Methods
cast_field(value, options)
click to toggle source
# File lib/aliyun/log/record/type_casting.rb, line 16 def self.cast_field(value, options) options ||= {} type = options[:cast_type] type ||= TYPE_MAPPING[options[:type]] return value if options.nil? return nil if value.nil? caster = Registry.lookup(type) raise ArgumentError, "Unknown type #{options[:type]}" if caster.nil? caster.new(options).cast(value) end
dump_field(value, options)
click to toggle source
# File lib/aliyun/log/record/type_casting.rb, line 30 def self.dump_field(value, options) options ||= {} type = options[:cast_type] type ||= TYPE_MAPPING[options[:type]] return value if options.nil? return nil if value.nil? dumper = Registry.lookup(type) raise ArgumentError, "Unknown type #{options[:type]}" if dumper.nil? dumper.new(options).dump(value) end