DeclaredPropertyManager

The DeclaredPropertyuManager holds details about objects created as a result of calling the #property class method on a class that includes Neo4j::ActiveNode or Neo4j::ActiveRel. There are many options that are referenced frequently, particularly during load and save, so this provides easy access and a way of separating behavior from the general Active{obj} modules.

See Neo4j::Shared::DeclaredProperty for definitions of the property objects themselves.

Constants

Methods

#attributes_nil_hash

During object wrap, a hash is needed that contains each declared property with a nil value. The active_attr dependency is capable of providing this but it is expensive and calculated on the fly each time it is called. Rather than rely on that, we build this progressively as properties are registered. When the node or rel is loaded, this is used as a template.

+ show/hide code
#attributes_string_map

During object wrapping, a props hash is built with string keys but Neo4j-core provides symbols. Rather than a to_s or symbolize_keys during every load, we build a map of symbol-to-string to speed up the process. This increases memory used by the gem but reduces object allocation and GC, so it is faster in practice.

+ show/hide code
#convert_properties_to

Modifies a hash’s values to be of types acceptable to Neo4j or matching what the user defined using type in property definitions.

+ show/hide code
#convert_property

Converts a single property from its current format to its db- or Ruby-expected output type.

+ show/hide code
#declared_property_defaults

The :default option in Neo4j::ActiveNode#property class method allows for setting a default value instead of nil on declared properties. This holds those values.

+ show/hide code
#initialize

Each class that includes Neo4j::ActiveNode or Neo4j::ActiveRel gets one instance of this class.

+ show/hide code
#klass

Returns the value of attribute klass

+ show/hide code

#magic_typecast_properties

+ show/hide code

#magic_typecast_properties_keys

+ show/hide code
#register

#property on an ActiveNode or ActiveRel class. The DeclaredProperty has specifics about the property, but registration makes the management object aware of it. This is necessary for type conversion, defaults, and inclusion in the nil and string hashes.

+ show/hide code

#registered_properties

+ show/hide code

#serialize

+ show/hide code

#serialized_properties

+ show/hide code

#serialized_properties=

+ show/hide code

#serialized_properties_keys

+ show/hide code
#string_key

but when this happens many times while loading many objects, it results in a surprisingly significant slowdown. The branching logic handles what happens if a property can’t be found. The first option attempts to find it in the existing hash. The second option checks whether the key is the class’s id property and, if it is, the string hash is rebuilt with it to prevent future lookups. The third calls to_s. This would happen if undeclared properties are found on the object. We could add them to the string map but that would result in unchecked, un-GCed memory consumption. In the event that someone is adding properties dynamically, maybe through user input, this would be bad.

+ show/hide code

#unregister

+ show/hide code
#upstream_primitives

The known mappings of declared properties and their primitive types.

+ show/hide code

#value_for_db

+ show/hide code

#value_for_ruby

+ show/hide code