TypeConverters¶
Constants¶
- CONVERTERS
Methods¶
def converter_for(type) type.respond_to?(:db_type) ? type : CONVERTERS[type] end
def included(_) Neo4j::Shared::TypeConverters.constants.each do |constant_name| constant = Neo4j::Shared::TypeConverters.const_get(constant_name) register_converter(constant) if constant.respond_to?(:convert_type) end end
def register_converter(converter) CONVERTERS[converter.convert_type] = converter end
def to_other(direction, value, type) fail "Unknown direction given: #{direction}" unless direction == :to_ruby || direction == :to_db found_converter = converter_for(type) return value unless found_converter return value if direction == :to_db && formatted_for_db?(found_converter, value) found_converter.send(direction, value) end
def typecast_attribute(typecaster, value) fail ArgumentError, "A typecaster must be given, #{typecaster} is invalid" unless typecaster.respond_to?(:to_ruby) return value if value.nil? typecaster.to_ruby(value) end
#typecast_attribute
def typecast_attribute(typecaster, value) Neo4j::Shared::TypeConverters.typecast_attribute(typecaster, value) end
def typecaster_for(value) Neo4j::Shared::TypeConverters.typecaster_for(value) end
.typecaster_for
def typecaster_for(primitive_type) return nil if primitive_type.nil? CONVERTERS[primitive_type] end