neo4j 5.2.13 → 5.2.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abf8d81e7dc5232e07dda9796367061233e4716e
4
- data.tar.gz: b7e00df2c8d8a10ef2fb1a148d53b17c36990879
3
+ metadata.gz: f213593268bdbcf3ca457f605bf2df1f86b7dc01
4
+ data.tar.gz: 3daa420d673284f5ceba6b259725713271925783
5
5
  SHA512:
6
- metadata.gz: 5278a649bb303704ed2205671dd68712a688082290791e82a65a8bf6143ad0c1d7883078f003825944bf426cc0ba4e4b826d7fce602421fae105f34f69acfdfd
7
- data.tar.gz: a44d10311b87b63ff3a85ddcdc8faa4fee4a9a815580140cfdcff2db8bb47777e9867ae664fa09cd24ca911f5cc8c31fe49aa5e3b62a904f8645570aef2d8106
6
+ metadata.gz: 5206d87f81b88acde44706e8e292cc0c80fdfba49f3cc1b2ebe1d2041f1a57f8b7e96b3125dcbbbe8acdf81a855c055d4b4a8545c372e7266050022b80ad81df
7
+ data.tar.gz: 30555f314d1f1aaabd691dc841853ffa04e9d65e337dc7930e1b20ff00aaa37afa7431a3a4c1e07e3a488c13c57db3bd986899a4096e21a475e8e5306fc26f6a
@@ -130,9 +130,8 @@ module Neo4j::ActiveNode
130
130
 
131
131
  def find_or_create(find_attributes, set_attributes = {})
132
132
  on_create_attributes = set_attributes.merge(on_create_props(find_attributes))
133
- on_match_attributes = set_attributes.merge(on_match_props)
134
133
  neo4j_session.query.merge(n: {self.mapped_label_names => find_attributes})
135
- .on_create_set(n: on_create_attributes).on_match_set(n: on_match_attributes)
134
+ .on_create_set(n: on_create_attributes)
136
135
  .pluck(:n).first
137
136
  end
138
137
 
@@ -27,16 +27,13 @@ module Neo4j
27
27
  attribute_descriptions = attribute_pairs.join(', ')
28
28
  separator = ' ' unless attribute_descriptions.empty?
29
29
 
30
- cypher_representation = "#{node_cypher_representation(from_node)}-[:#{type}]->#{node_cypher_representation(to_node)}"
30
+ cypher_representation = "#{node_cypher_representation(:from)}-[:#{type}]->#{node_cypher_representation(:to)}"
31
31
  "#<#{self.class.name} #{cypher_representation}#{separator}#{attribute_descriptions}>"
32
32
  end
33
33
 
34
- def node_cypher_representation(node)
35
- node_class = node.class
36
- id_name = node_class.id_property_name
37
- labels = ':' + node_class.mapped_label_names.join(':')
38
-
39
- "(#{labels} {#{id_name}: #{node.id.inspect}})"
34
+ def node_cypher_representation(direction)
35
+ node = send(:"#{direction}_node")
36
+ node.cypher_representation(self.class.send(:"#{direction}_class"))
40
37
  end
41
38
 
42
39
  def neo4j_obj
@@ -4,6 +4,7 @@ module Neo4j::ActiveRel
4
4
  # will result in a query to load the node if the node is not already loaded.
5
5
  class RelatedNode
6
6
  class InvalidParameterError < StandardError; end
7
+ class UnsetRelatedNodeError < StandardError; end
7
8
 
8
9
  # ActiveRel's related nodes can be initialized with nothing, an integer, or a fully wrapped node.
9
10
  #
@@ -30,20 +31,41 @@ module Neo4j::ActiveRel
30
31
 
31
32
  # Loads a node from the database or returns the node if already laoded
32
33
  def loaded
34
+ fail NilRelatedNodeError, 'Node not set, cannot load' if @node.nil?
33
35
  @node = @node.respond_to?(:neo_id) ? @node : Neo4j::Node.load(@node)
34
36
  end
35
37
 
38
+ # @param [String, Symbol, Array] clazz An alternate label to use in the event the node is not present or loaded
39
+ def cypher_representation(clazz)
40
+ case
41
+ when !set?
42
+ "(#{formatted_label_list(clazz)})"
43
+ when set? && !loaded?
44
+ "(Node with neo_id #{@node})"
45
+ else
46
+ node_class = self.class
47
+ id_name = node_class.id_property_name
48
+ labels = ':' + node_class.mapped_label_names.join(':')
49
+
50
+ "(#{labels} {#{id_name}: #{@node.id.inspect}})"
51
+ end
52
+ end
53
+
36
54
  # @return [Boolean] indicates whether a node has or has not been fully loaded from the database
37
55
  def loaded?
38
56
  @node.respond_to?(:neo_id)
39
57
  end
40
58
 
59
+ def set?
60
+ !@node.nil?
61
+ end
62
+
41
63
  def method_missing(*args, &block)
42
64
  loaded.send(*args, &block)
43
65
  end
44
66
 
45
67
  def respond_to_missing?(method_name, include_private = false)
46
- loaded if @node.is_a?(Integer)
68
+ loaded if @node.is_a?(Numeric)
47
69
  @node.respond_to?(method_name) ? true : super
48
70
  end
49
71
 
@@ -53,6 +75,10 @@ module Neo4j::ActiveRel
53
75
 
54
76
  private
55
77
 
78
+ def formatted_label_list(list)
79
+ list.is_a?(Array) ? list.join(' || ') : list
80
+ end
81
+
56
82
  def valid_node_param?(node)
57
83
  node.nil? || node.is_a?(Integer) || node.respond_to?(:neo_id)
58
84
  end
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '5.2.13'
2
+ VERSION = '5.2.14'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.13
4
+ version: 5.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Brian Underwood, Chris Grigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter