module ActiveGraph::Shared::Initialize
Public Instance Methods
wrapper()
click to toggle source
Implements the ActiveGraph::Node#wrapper and ActiveGraph::Relationship#wrapper method so that we don't have to care if the node is wrapped or not. @return self
# File lib/active_graph/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/active_graph/shared/initialize.rb 33 def changed_attributes_clear! 34 return if changed_attributes.nil? 35 36 # with ActiveModel 6.0.0 we have to clear attribute changes with clear_attribute_changes 37 clear_attribute_changes(self.attributes.keys) 38 39 # changed_attributes is frozen starting with ActiveModel 5.2.0 40 # Not a good long term solution 41 if changed_attributes.frozen? 42 @attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new 43 else 44 changed_attributes && changed_attributes.clear 45 end 46 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/active_graph/shared/initialize.rb 50 def changed_attributes_selective_clear!(hash_to_clear) 51 # with ActiveModel 6.0.0 we have to clear attribute changes with clear_attribute_change 52 hash_to_clear.each_key { |k| clear_attribute_change(k) } if defined?(ActiveModel::ForcedMutationTracker) 53 54 # changed_attributes is frozen starting with ActiveModel 5.2.0 55 # Not a good long term solution 56 if changed_attributes.frozen? 57 attributes_changed_by_setter = ActiveSupport::HashWithIndifferentAccess.new(changed_attributes) 58 hash_to_clear.each_key { |k| attributes_changed_by_setter.delete(k) } 59 @attributes_changed_by_setter = attributes_changed_by_setter 60 else 61 hash_to_clear.each_key { |k| changed_attributes.delete(k) } 62 end 63 end
convert_and_assign_attributes(properties)
click to toggle source
# File lib/active_graph/shared/initialize.rb 14 def convert_and_assign_attributes(properties) 15 @attributes ||= ActiveGraph::AttributeSet.new(self.class.attributes_nil_hash, self.class.attributes.keys) 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 @attributes 20 end
stringify_attributes!(attr, properties)
click to toggle source
# File lib/active_graph/shared/initialize.rb 22 def stringify_attributes!(attr, properties) 23 properties.each_pair do |k, v| 24 key = self.class.declared_properties.string_key(k) 25 attr.write_cast_value(key.freeze, v) 26 end 27 end