module Neo4j::Shared::Initialize
Public Instance Methods
wrapper()
click to toggle source
Implements the Neo4j::Node#wrapper and Neo4j::Relationship#wrapper method so that we don't have to care if the node is wrapped or not. @return self
# File lib/neo4j/shared/initialize.rb 8 def wrapper 9 self 10 end
Private Instance Methods
changed_attributes_clear!()
click to toggle source
We should be using clear_changes_information but right now we don't use `ActiveModel` attributes correctly and so it doesn't work Once we set @attribute correctly from using class ActiveModel::Attribute we will no longer need to explicitly call following method and can safely remove it
# File lib/neo4j/shared/initialize.rb 32 def changed_attributes_clear! 33 return if changed_attributes.nil? 34 35 # with ActiveModel 6.0.0 we have to clear attribute changes with clear_attribute_changes 36 clear_attribute_changes(self.attributes.keys) 37 38 # changed_attributes is frozen starting with ActiveModel 5.2.0 39 # Not a good long term solution 40 if changed_attributes.frozen? 41 @attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new 42 else 43 changed_attributes && changed_attributes.clear 44 end 45 end
changed_attributes_selective_clear!(hash_to_clear)
click to toggle source
Once we set @attribute correctly from using class ActiveModel::Attribute we will no longer need to explicitly call following method and can safely remove it
# File lib/neo4j/shared/initialize.rb 49 def changed_attributes_selective_clear!(hash_to_clear) 50 # with ActiveModel 6.0.0 we have to clear attribute changes with clear_attribute_change 51 hash_to_clear.each_key { |k| clear_attribute_change(k) } if defined?(ActiveModel::ForcedMutationTracker) 52 53 # changed_attributes is frozen starting with ActiveModel 5.2.0 54 # Not a good long term solution 55 if changed_attributes.frozen? 56 attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new(changed_attributes) 57 hash_to_clear.each_key { |k| attributes_changed_by_setter.delete(k) } 58 @attributes_changed_by_setter = attributes_changed_by_setter 59 else 60 hash_to_clear.each_key { |k| changed_attributes.delete(k) } 61 end 62 end
convert_and_assign_attributes(properties)
click to toggle source
# File lib/neo4j/shared/initialize.rb 14 def convert_and_assign_attributes(properties) 15 @attributes ||= Hash[self.class.attributes_nil_hash] 16 stringify_attributes!(@attributes, properties) 17 self.default_properties = properties if respond_to?(:default_properties=) 18 self.class.declared_properties.convert_properties_to(self, :ruby, @attributes) 19 end
stringify_attributes!(attr, properties)
click to toggle source
# File lib/neo4j/shared/initialize.rb 21 def stringify_attributes!(attr, properties) 22 properties.each_pair do |k, v| 23 key = self.class.declared_properties.string_key(k) 24 attr[key.freeze] = v 25 end 26 end