module Neo4j::ActiveRel::Persistence
Public Instance Methods
concurrent_increment!(attribute, by = 1)
click to toggle source
Increments concurrently a numeric attribute by a centain amount @param [Symbol, String] name of the attribute to increment @param [Integer, Float] amount to increment
# File lib/neo4j/active_rel/persistence.rb 42 def concurrent_increment!(attribute, by = 1) 43 increment_by_query! query_as(:r), attribute, by, :r 44 end
create_method()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 92 def create_method 93 self.class.create_method 94 end
create_model()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 46 def create_model 47 validate_node_classes! 48 validate_has_one_rel 49 rel = _create_rel 50 return self unless rel.respond_to?(:props) 51 init_on_load(rel, from_node, to_node, @rel_type) 52 true 53 end
cypher_identifier()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 27 def cypher_identifier 28 @cypher_identifier || :rel 29 end
from_node_identifier()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 11 def from_node_identifier 12 @from_node_identifier || :from_node 13 end
from_node_identifier=(id)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 19 def from_node_identifier=(id) 20 @from_node_identifier = id.to_sym 21 end
query_as(var)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 61 def query_as(var) 62 # This should query based on the nodes, not the rel neo_id, I think 63 # Also, picky point: Should the var be `n`? 64 self.class.query_as(neo_id, var) 65 end
save(*)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 31 def save(*) 32 create_or_update 33 end
save!(*args)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 35 def save!(*args) 36 save(*args) or fail(RelInvalidError, inspect) # rubocop:disable Style/AndOr 37 end
to_node_identifier()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 15 def to_node_identifier 16 @to_node_identifier || :to_node 17 end
to_node_identifier=(id)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 23 def to_node_identifier=(id) 24 @to_node_identifier = id.to_sym 25 end
validate_has_one_rel()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 55 def validate_has_one_rel 56 return unless Neo4j::Config[:enforce_has_one] 57 to_node.validate_reverse_has_one_active_rel(self, :in, from_node) if to_node.persisted? 58 from_node.validate_reverse_has_one_active_rel(self, :out, to_node) if from_node.persisted? 59 end
Private Instance Methods
_create_rel()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 128 def _create_rel 129 factory = QueryFactory.new(from_node, to_node, self) 130 factory.build! 131 factory.unwrapped_rel 132 end
destroy_query()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 98 def destroy_query 99 query_as(:r).delete(:r) 100 end
type_validation_error_message(node, type_class)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 124 def type_validation_error_message(node, type_class) 125 "Node class was #{node.class} (#{node.class.object_id}), expected #{type_class} (#{type_class.object_id})" 126 end
valid_type?(type_object, node)
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 113 def valid_type?(type_object, node) 114 case type_object 115 when false, :any 116 true 117 when Array 118 type_object.any? { |c| valid_type?(c, node) } 119 else 120 node.class.mapped_label_names.include?(type_object.to_s.constantize.mapped_label_name) 121 end 122 end
validate_node_classes!()
click to toggle source
# File lib/neo4j/active_rel/persistence.rb 102 def validate_node_classes! 103 [from_node, to_node].each do |node| 104 type = from_node == node ? :_from_class : :_to_class 105 type_class = self.class.send(type) 106 107 unless valid_type?(type_class, node) 108 fail ModelClassInvalidError, type_validation_error_message(node, type_class) 109 end 110 end 111 end