neo4j 5.0.2 → 5.0.3

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: 2f494789056a2cf7cdf67ad93320d087aec27ef9
4
- data.tar.gz: d20cf2ef3016d84ecf8ddc85a68b3224518a424e
3
+ metadata.gz: a74b7d45b24d73d7a6b74a9fd422ac3868812a1e
4
+ data.tar.gz: af35506b1d68f73313ab0dea22328c5cb9233186
5
5
  SHA512:
6
- metadata.gz: 059712836b2762ba02ea73fa4c0581a24cea4d9c10e87da127c0be60a8288c0a4e4b376f7b87836e8277ff78f6be1b44b8bff7832db96a320d738ac5ddde976d
7
- data.tar.gz: 34a29e62bee5492358d3ab93ac3b18c06455480d4c3cd3d54b0fa5f78875c792d2aaee0f6b73c9cdba8254c6d8a31276960b3078213f9db14ebed915b4595300
6
+ metadata.gz: 2b49582690880a513369153e59db263e513dd437baa090406f051b0e05059a67026761f84b46a42b31fdb4afb1de4ecc35aea7a19e5ff3e273e7aa9aea5617a5
7
+ data.tar.gz: 9f74ec13fee9f81dadd6aacaf59fd1845623fb939be6ff90742f761f46b5ab8348b72efa47765c23dbff89f5bbc7f0ae12b67cf8bc6e1de4654bd5bac1604b46
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ### Changed
9
+ - `ActiveNode#destroyed?` and `ActiveRel#destroyed?` now only consider the in-memory state of if an object is destroyed without checking the database
10
+ - Moved `#with_associations` method from `AssociationProxy` to `QueryProxy` so that all `QueryProxy` chains can benefit from it.
11
+
8
12
  ## [5.0.2] - 2015-06-30
9
13
 
10
14
  ### Fixed
@@ -6,7 +6,8 @@ module Neo4j
6
6
  class Association
7
7
  include Neo4j::Shared::RelTypeConverters
8
8
  include Neo4j::ActiveNode::Dependent::AssociationMethods
9
- attr_reader :type, :name, :relationship, :direction, :dependent
9
+
10
+ attr_reader :type, :name, :relationship, :direction, :dependent, :model_class
10
11
 
11
12
  def initialize(type, direction, name, options = {type: nil})
12
13
  validate_init_arguments(type, direction, name, options)
@@ -58,10 +59,22 @@ module Neo4j
58
59
  end
59
60
  end
60
61
 
62
+ def target_classes
63
+ target_class_names.map(&:constantize)
64
+ end
65
+
61
66
  def target_classes_or_nil
62
67
  @target_classes_or_nil ||= discovered_model if target_class_names
63
68
  end
64
69
 
70
+ def target_where_clause
71
+ return if model_class == false
72
+
73
+ Array.new(target_classes).map do |target_class|
74
+ "#{name}:#{target_class.mapped_label_name}"
75
+ end.join(' OR ')
76
+ end
77
+
65
78
  def discovered_model
66
79
  target_class_names.map(&:constantize).select do |constant|
67
80
  constant.ancestors.include?(::Neo4j::ActiveNode)
@@ -87,12 +100,9 @@ module Neo4j
87
100
 
88
101
  def relationship_type(create = false)
89
102
  case
90
- when relationship_class
91
- relationship_class_type
92
- when @relationship_type
93
- @relationship_type
94
- when @origin
95
- origin_type
103
+ when relationship_class then relationship_class_type
104
+ when @relationship_type then @relationship_type
105
+ when @origin then origin_type
96
106
  else
97
107
  (create || exceptional_target_class?) && decorated_rel_type(@name)
98
108
  end
@@ -130,12 +140,9 @@ module Neo4j
130
140
 
131
141
  def direction_cypher(relationship_cypher, create, reverse = false)
132
142
  case get_direction(create, reverse)
133
- when :out
134
- "-#{relationship_cypher}->"
135
- when :in
136
- "<-#{relationship_cypher}-"
137
- when :both
138
- "-#{relationship_cypher}-"
143
+ when :out then "-#{relationship_cypher}->"
144
+ when :in then "<-#{relationship_cypher}-"
145
+ when :both then "-#{relationship_cypher}-"
139
146
  end
140
147
  end
141
148
 
@@ -84,26 +84,8 @@ module Neo4j::ActiveNode
84
84
  target.public_send(method_name, *args, &block)
85
85
  end
86
86
 
87
- def with_associations(*spec)
88
- return_object_clause = '[' + spec.map { |n| "collect(#{n})" }.join(',') + ']'
89
- query_from_association_spec(spec).pluck(:previous, return_object_clause).map do |record, eager_data|
90
- eager_data.each_with_index do |eager_records, index|
91
- record.send(spec[index]).cache_result(eager_records)
92
- end
93
-
94
- record
95
- end
96
- end
97
-
98
87
  private
99
88
 
100
- def query_from_association_spec(spec)
101
- spec.inject(@query_proxy.query_as(:previous).return(:previous)) do |query, association_name|
102
- association = @query_proxy.model.associations[association_name]
103
- query.optional_match("previous#{association.arrow_cypher}#{association_name}")
104
- end
105
- end
106
-
107
89
  def target_for_missing_method(method_name)
108
90
  case method_name
109
91
  when *QUERY_PROXY_METHODS
@@ -5,6 +5,7 @@ module Neo4j
5
5
  include Neo4j::ActiveNode::Query::QueryProxyEnumerable
6
6
  include Neo4j::ActiveNode::Query::QueryProxyMethods
7
7
  include Neo4j::ActiveNode::Query::QueryProxyFindInBatches
8
+ include Neo4j::ActiveNode::Query::QueryProxyEagerLoading
8
9
  include Neo4j::ActiveNode::Dependent::QueryProxyMethods
9
10
 
10
11
  # The most recent node to start a QueryProxy chain.
@@ -37,6 +38,7 @@ module Neo4j
37
38
  @association = association
38
39
  @context = options.delete(:context)
39
40
  @options = options
41
+ @associations_spec = []
40
42
 
41
43
  instance_vars_from_options!(options)
42
44
 
@@ -317,8 +319,8 @@ module Neo4j
317
319
  end
318
320
 
319
321
  def build_deeper_query_proxy(method, args)
320
- new_link.tap do |new_query|
321
- Link.for_args(@model, method, args).each { |link| new_query._add_links(link) }
322
+ new_link.tap do |new_query_proxy|
323
+ Link.for_args(@model, method, args).each { |link| new_query_proxy._add_links(link) }
322
324
  end
323
325
  end
324
326
  end
@@ -0,0 +1,46 @@
1
+ module Neo4j
2
+ module ActiveNode
3
+ module Query
4
+ module QueryProxyEagerLoading
5
+ def initialize(model, association = nil, options = {})
6
+ @associations_spec = []
7
+
8
+ super
9
+ end
10
+
11
+ def each(node = true, rel = nil, &block)
12
+ if @associations_spec.size > 0
13
+ return_object_clause = '[' + @associations_spec.map { |n| "collect(#{n})" }.join(',') + ']'
14
+ query_from_association_spec.pluck(identity, return_object_clause).map do |record, eager_data|
15
+ eager_data.each_with_index do |eager_records, index|
16
+ record.association_proxy(@associations_spec[index]).cache_result(eager_records)
17
+ end
18
+
19
+ block.call(record)
20
+ end
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def with_associations(*spec)
27
+ new_link.tap do |new_query_proxy|
28
+ new_spec = new_query_proxy.instance_variable_get('@associations_spec') + spec
29
+ new_query_proxy.instance_variable_set('@associations_spec', new_spec)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def query_from_association_spec
36
+ @associations_spec.inject(query_as(identity).return(identity)) do |query, association_name|
37
+ association = model.associations[association_name]
38
+
39
+ query.optional_match("#{identity}#{association.arrow_cypher}#{association_name}")
40
+ .where(association.target_where_clause)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -78,9 +78,25 @@ module Neo4j::Shared
78
78
 
79
79
  # Returns +true+ if the object was destroyed.
80
80
  def destroyed?
81
- @_deleted || (!new_record? && !exist?)
81
+ @_deleted || _destroyed_double_check?
82
82
  end
83
83
 
84
+ # These two methods should be removed in 6.0.0
85
+ def _destroyed_double_check?
86
+ if _active_record_destroyed_behavior?
87
+ true
88
+ else
89
+ (!new_record? && !exist?)
90
+ end
91
+ end
92
+
93
+ def _active_record_destroyed_behavior?
94
+ fail 'Remove this workaround in 6.0.0' if Neo4j::VERSION >= '6.0.0'
95
+
96
+ !!Neo4j::Config[:_active_record_destroyed_behavior]
97
+ end
98
+ # End of two methods which should be removed in 6.0.0
99
+
84
100
 
85
101
  # @return [Hash] all defined and none nil properties
86
102
  def props
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '5.0.2'
2
+ VERSION = '5.0.3'
3
3
  end
data/lib/neo4j.rb CHANGED
@@ -55,6 +55,7 @@ require 'neo4j/active_node/query_methods'
55
55
  require 'neo4j/active_node/query/query_proxy_methods'
56
56
  require 'neo4j/active_node/query/query_proxy_enumerable'
57
57
  require 'neo4j/active_node/query/query_proxy_find_in_batches'
58
+ require 'neo4j/active_node/query/query_proxy_eager_loading'
58
59
  require 'neo4j/active_node/query/query_proxy_link'
59
60
  require 'neo4j/active_node/labels'
60
61
  require 'neo4j/active_node/id_property'
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.0.2
4
+ version: 5.0.3
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter
@@ -240,6 +240,7 @@ files:
240
240
  - lib/neo4j/active_node/property.rb
241
241
  - lib/neo4j/active_node/query.rb
242
242
  - lib/neo4j/active_node/query/query_proxy.rb
243
+ - lib/neo4j/active_node/query/query_proxy_eager_loading.rb
243
244
  - lib/neo4j/active_node/query/query_proxy_enumerable.rb
244
245
  - lib/neo4j/active_node/query/query_proxy_find_in_batches.rb
245
246
  - lib/neo4j/active_node/query/query_proxy_link.rb