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   query_rel = Neo4j::Session.query.match('()-[n]-()').where(n: {neo_id: neo_id})
44   increment_by_query! query_rel, attribute, by
45 end
create_method() click to toggle source
   # File lib/neo4j/active_rel/persistence.rb
76 def create_method
77   self.class.create_method
78 end
create_model() click to toggle source
   # File lib/neo4j/active_rel/persistence.rb
47 def create_model
48   validate_node_classes!
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
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

Private Instance Methods

_create_rel() click to toggle source
    # File lib/neo4j/active_rel/persistence.rb
108 def _create_rel
109   factory = QueryFactory.new(from_node, to_node, self)
110   factory.build!
111   factory.unwrapped_rel
112 end
type_validation_error_message(node, type_class) click to toggle source
    # File lib/neo4j/active_rel/persistence.rb
104 def type_validation_error_message(node, type_class)
105   "Node class was #{node.class} (#{node.class.object_id}), expected #{type_class} (#{type_class.object_id})"
106 end
valid_type?(type_object, node) click to toggle source
    # File lib/neo4j/active_rel/persistence.rb
 93 def valid_type?(type_object, node)
 94   case type_object
 95   when false, :any
 96     true
 97   when Array
 98     type_object.any? { |c| valid_type?(c, node) }
 99   else
100     node.class.mapped_label_names.include?(type_object.to_s.constantize.mapped_label_name)
101   end
102 end
validate_node_classes!() click to toggle source
   # File lib/neo4j/active_rel/persistence.rb
82 def validate_node_classes!
83   [from_node, to_node].each do |node|
84     type = from_node == node ? :_from_class : :_to_class
85     type_class = self.class.send(type)
86 
87     unless valid_type?(type_class, node)
88       fail ModelClassInvalidError, type_validation_error_message(node, type_class)
89     end
90   end
91 end