neo4j 5.0.0.rc.3 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/lib/neo4j/active_node.rb +9 -0
- data/lib/neo4j/active_node/has_n.rb +7 -17
- data/lib/neo4j/active_node/query/query_proxy.rb +13 -22
- data/lib/neo4j/active_node/query/query_proxy_methods.rb +16 -0
- data/lib/neo4j/shared/declared_property.rb +0 -4
- data/lib/neo4j/shared/identity.rb +1 -1
- data/lib/neo4j/shared/type_converters.rb +4 -0
- data/lib/neo4j/version.rb +1 -1
- data/neo4j.gemspec +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df42076f21c3f31cf2cde7b6d226af5c3f27ffd4
|
4
|
+
data.tar.gz: 284cff951e6666fe88f49147c05d89f59be231fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd03334a23759e25ecf0aa6a3586ad8b08b8650312505254e84e06e43502fab6e1ae775f9b86218db686baefdfec11e8078dfd7de378bcffe0ac1055682bc2bc
|
7
|
+
data.tar.gz: 408d0968f7796141d8f04f81fd91b08e859141001285eba1a7f4d79f30ad2be8a2f3f7ed46964b853743e497f9726c8d8b615f3ad3f3508fac132e9f0a946db5
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
## [Unreleased][unreleased]
|
7
7
|
- Nothing yet, placeholder
|
8
8
|
|
9
|
-
## [5.0.0
|
9
|
+
## [5.0.0] - 2015-06-18
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Prevented `to_key` from requiring an extra DB query. (See https://github.com/neo4jrb/neo4j/pull/827)
|
13
|
+
|
14
|
+
### Added
|
15
|
+
- QueryProxy associations accept `labels: false` option to prevent generated Cypher from using labels.
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
- Properties explicitly set to type `Time` will no longer be converted to `DateTime`.
|
19
|
+
|
20
|
+
## [5.0.0.rc.3] - 2015-06-07
|
10
21
|
|
11
22
|
### Fixed
|
12
23
|
- Associations now allow `unique` option. Error handling is generalized to make this testable (Thanks to @olance, see #824)
|
data/lib/neo4j/active_node.rb
CHANGED
@@ -44,6 +44,15 @@ module Neo4j
|
|
44
44
|
_persisted_obj || fail('Tried to access native neo4j object on a non persisted object')
|
45
45
|
end
|
46
46
|
|
47
|
+
def inspect
|
48
|
+
id_property_name = self.class.id_property_name.to_s
|
49
|
+
attribute_pairs = attributes.except(id_property_name).sort.map { |key, value| "#{key}: #{value.inspect}" }
|
50
|
+
attribute_pairs.unshift("#{id_property_name}: #{self.send(id_property_name).inspect}")
|
51
|
+
attribute_descriptions = attribute_pairs.join(', ')
|
52
|
+
separator = ' ' unless attribute_descriptions.empty?
|
53
|
+
"#<#{self.class.name}#{separator}#{attribute_descriptions}>"
|
54
|
+
end
|
55
|
+
|
47
56
|
included do
|
48
57
|
def self.inherited(other)
|
49
58
|
inherit_id_property(other)
|
@@ -138,22 +138,13 @@ module Neo4j::ActiveNode
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
# Uses the cypher generated by a QueryProxy object, complete with params, to generate a basic non-cryptographic hash
|
142
|
-
# for use in @association_cache.
|
143
|
-
# @param [String] the cypher used in the query
|
144
|
-
# @return [String] A basic hash of the query
|
145
|
-
def cypher_hash(cypher_string)
|
146
|
-
cypher_string.hash.abs
|
147
|
-
end
|
148
|
-
|
149
141
|
def association_query_proxy(name, options = {})
|
150
|
-
self.class.send(:association_query_proxy, name, {start_object: self}.merge(options))
|
142
|
+
self.class.send(:association_query_proxy, name, {start_object: self}.merge!(options))
|
151
143
|
end
|
152
144
|
|
153
145
|
def association_proxy(name, options = {})
|
154
146
|
name = name.to_sym
|
155
|
-
hash = [name, options.values_at(:node, :rel)].hash
|
156
|
-
|
147
|
+
hash = [name, options.values_at(:node, :rel, :labels)].hash
|
157
148
|
association_proxy_cache_fetch(hash) do
|
158
149
|
if previous_association_proxy = self.instance_variable_get('@association_proxy')
|
159
150
|
result_by_previous_id = previous_association_proxy_results_by_previous_id(previous_association_proxy, name)
|
@@ -321,13 +312,13 @@ module Neo4j::ActiveNode
|
|
321
312
|
define_method(name) do |node = nil, rel = nil, options = {}|
|
322
313
|
return [].freeze unless self._persisted_obj
|
323
314
|
|
324
|
-
association_proxy(name, {node: node, rel: rel, source_object: self}.merge(options))
|
315
|
+
association_proxy(name, {node: node, rel: rel, source_object: self, labels: options[:labels]}.merge!(options))
|
325
316
|
end
|
326
317
|
|
327
318
|
define_has_many_setter(name)
|
328
319
|
|
329
320
|
define_class_method(name) do |node = nil, rel = nil, options = {}|
|
330
|
-
association_proxy(name, {node: node, rel: rel}.merge(options))
|
321
|
+
association_proxy(name, {node: node, rel: rel, labels: options[:labels]}.merge!(options))
|
331
322
|
end
|
332
323
|
end
|
333
324
|
|
@@ -349,7 +340,7 @@ module Neo4j::ActiveNode
|
|
349
340
|
define_has_one_setter(name)
|
350
341
|
|
351
342
|
define_class_method(name) do |node = nil, rel = nil, options = {}|
|
352
|
-
association_proxy(name, {node: node, rel: rel}.merge(options))
|
343
|
+
association_proxy(name, {node: node, rel: rel, labels: options[:labels]}.merge!(options))
|
353
344
|
end
|
354
345
|
end
|
355
346
|
|
@@ -373,14 +364,14 @@ module Neo4j::ActiveNode
|
|
373
364
|
def association_query_proxy(name, options = {})
|
374
365
|
previous_query_proxy = options[:previous_query_proxy] || current_scope
|
375
366
|
query_proxy = previous_query_proxy || default_association_query_proxy(name)
|
376
|
-
|
377
367
|
Neo4j::ActiveNode::Query::QueryProxy.new(association_target_class(name),
|
378
368
|
associations[name],
|
379
369
|
{session: neo4j_session,
|
380
370
|
query_proxy: query_proxy,
|
381
371
|
context: "#{query_proxy.context || self.name}##{name}",
|
382
372
|
optional: query_proxy.optional?,
|
383
|
-
|
373
|
+
association_labels: options[:labels],
|
374
|
+
source_object: query_proxy.source_object}.merge!(options)).tap do |query_proxy_result|
|
384
375
|
target_classes = association_target_classes(name)
|
385
376
|
return query_proxy_result.as_models(target_classes) if target_classes
|
386
377
|
end
|
@@ -388,7 +379,6 @@ module Neo4j::ActiveNode
|
|
388
379
|
|
389
380
|
def association_proxy(name, options = {})
|
390
381
|
query_proxy = association_query_proxy(name, options)
|
391
|
-
|
392
382
|
AssociationProxy.new(query_proxy)
|
393
383
|
end
|
394
384
|
|
@@ -38,8 +38,7 @@ module Neo4j
|
|
38
38
|
@context = options.delete(:context)
|
39
39
|
@options = options
|
40
40
|
|
41
|
-
|
42
|
-
options.values_at(:node, :session, :source_object, :starting_query, :optional, :start_object, :query_proxy, :chain_level)
|
41
|
+
instance_vars_from_options!(options)
|
43
42
|
|
44
43
|
@match_type = @optional ? :optional_match : :match
|
45
44
|
|
@@ -86,8 +85,8 @@ module Neo4j
|
|
86
85
|
# and work with it from the more powerful (but less friendly) Neo4j::Core::Query.
|
87
86
|
# @param [String,Symbol] var The identifier to use for node at this link of the QueryProxy chain.
|
88
87
|
# student.lessons.query_as(:l).with('your cypher here...')
|
89
|
-
def query_as(var,
|
90
|
-
result_query = @chain.inject(base_query(var,
|
88
|
+
def query_as(var, with_labels = true)
|
89
|
+
result_query = @chain.inject(base_query(var, with_labels).params(@params)) do |query, link|
|
91
90
|
args = link.args(var, rel_var)
|
92
91
|
|
93
92
|
args.is_a?(Array) ? query.send(link.clause, *args) : query.send(link.clause, args)
|
@@ -106,8 +105,11 @@ module Neo4j
|
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
|
-
|
110
|
-
|
108
|
+
# param [TrueClass, FalseClass] with_labels This param is used by certain QueryProxy methods that already have the neo_id and
|
109
|
+
# therefore do not need labels.
|
110
|
+
# The @association_labels instance var is set during init and used during association chaining to keep labels out of Cypher queries.
|
111
|
+
def _model_label_string(with_labels = true)
|
112
|
+
return if !@model || (!with_labels || @association_labels == false)
|
111
113
|
@model.mapped_label_names.map { |label_name| ":`#{label_name}`" }.join
|
112
114
|
end
|
113
115
|
|
@@ -185,16 +187,6 @@ module Neo4j
|
|
185
187
|
end
|
186
188
|
end
|
187
189
|
|
188
|
-
def rels
|
189
|
-
fail 'Cannot get rels without a relationship variable.' if !@rel_var
|
190
|
-
|
191
|
-
pluck(@rel_var)
|
192
|
-
end
|
193
|
-
|
194
|
-
def rel
|
195
|
-
rels.first
|
196
|
-
end
|
197
|
-
|
198
190
|
def _nodeify!(*args)
|
199
191
|
other_nodes = [args].flatten!.map! do |arg|
|
200
192
|
(arg.is_a?(Integer) || arg.is_a?(String)) ? @model.find_by(@model.id_property_name => arg) : arg
|
@@ -232,12 +224,6 @@ module Neo4j
|
|
232
224
|
(@model && @model.respond_to?(method_name, include_all)) || super
|
233
225
|
end
|
234
226
|
|
235
|
-
# Give ability to call `#find` on associations to get a scoped find
|
236
|
-
# Doesn't pass through via `method_missing` because Enumerable has a `#find` method
|
237
|
-
def find(*args)
|
238
|
-
scoping { @model.find(*args) }
|
239
|
-
end
|
240
|
-
|
241
227
|
def optional?
|
242
228
|
@optional == true
|
243
229
|
end
|
@@ -325,6 +311,11 @@ module Neo4j
|
|
325
311
|
|
326
312
|
private
|
327
313
|
|
314
|
+
def instance_vars_from_options!(options)
|
315
|
+
@node_var, @session, @source_object, @starting_query, @optional, @start_object, @query_proxy, @chain_level, @association_labels =
|
316
|
+
options.values_at(:node, :session, :source_object, :starting_query, :optional, :start_object, :query_proxy, :chain_level, :association_labels)
|
317
|
+
end
|
318
|
+
|
328
319
|
def build_deeper_query_proxy(method, args)
|
329
320
|
new_link.tap do |new_query|
|
330
321
|
Link.for_args(@model, method, args).each { |link| new_query._add_links(link) }
|
@@ -6,6 +6,22 @@ module Neo4j
|
|
6
6
|
FIRST = 'HEAD'
|
7
7
|
LAST = 'LAST'
|
8
8
|
|
9
|
+
def rels
|
10
|
+
fail 'Cannot get rels without a relationship variable.' if !@rel_var
|
11
|
+
|
12
|
+
pluck(@rel_var)
|
13
|
+
end
|
14
|
+
|
15
|
+
def rel
|
16
|
+
rels.first
|
17
|
+
end
|
18
|
+
|
19
|
+
# Give ability to call `#find` on associations to get a scoped find
|
20
|
+
# Doesn't pass through via `method_missing` because Enumerable has a `#find` method
|
21
|
+
def find(*args)
|
22
|
+
scoping { @model.find(*args) }
|
23
|
+
end
|
24
|
+
|
9
25
|
def first(target = nil)
|
10
26
|
first_and_last(FIRST, target)
|
11
27
|
end
|
@@ -34,10 +34,6 @@ module Neo4j::Shared
|
|
34
34
|
# Tweaks properties
|
35
35
|
def register_magic_properties
|
36
36
|
options[:type] ||= DateTime if name.to_sym == :created_at || name.to_sym == :updated_at
|
37
|
-
# TODO: Custom typecaster to fix the stuff below
|
38
|
-
# ActiveAttr does not handle "Time", Rails and Neo4j.rb 2.3 did
|
39
|
-
# Convert it to DateTime in the interest of consistency
|
40
|
-
options[:type] = DateTime if options[:type] == Time
|
41
37
|
|
42
38
|
register_magic_typecaster
|
43
39
|
register_type_converter
|
@@ -8,7 +8,7 @@ module Neo4j::Shared
|
|
8
8
|
# Returns an Enumerable of all (primary) key attributes
|
9
9
|
# or nil if model.persisted? is false
|
10
10
|
def to_key
|
11
|
-
|
11
|
+
_persisted_obj ? [id] : nil
|
12
12
|
end
|
13
13
|
|
14
14
|
# @return [Integer, nil] the neo4j id of the node if persisted or nil
|
@@ -57,6 +57,9 @@ module Neo4j::Shared
|
|
57
57
|
Time
|
58
58
|
end
|
59
59
|
|
60
|
+
def primitive_type
|
61
|
+
Integer
|
62
|
+
end
|
60
63
|
# Converts the given DateTime (UTC) value to an Integer.
|
61
64
|
# Only utc times are supported !
|
62
65
|
def to_db(value)
|
@@ -70,6 +73,7 @@ module Neo4j::Shared
|
|
70
73
|
def to_ruby(value)
|
71
74
|
Time.at(value).utc
|
72
75
|
end
|
76
|
+
alias_method :call, :to_ruby
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
data/lib/neo4j/version.rb
CHANGED
data/neo4j.gemspec
CHANGED
@@ -30,7 +30,7 @@ A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks h
|
|
30
30
|
s.add_dependency('activemodel', '~> 4')
|
31
31
|
s.add_dependency('activesupport', '~> 4')
|
32
32
|
s.add_dependency('active_attr', '~> 0.8')
|
33
|
-
s.add_dependency('neo4j-core', '
|
33
|
+
s.add_dependency('neo4j-core', '~> 5.0.0')
|
34
34
|
s.add_dependency('neo4j-community', '~> 2.0') if RUBY_PLATFORM =~ /java/
|
35
35
|
s.add_development_dependency('railties', '~> 4')
|
36
36
|
s.add_development_dependency('pry')
|
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.0
|
4
|
+
version: 5.0.0
|
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-
|
11
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orm_adapter
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: neo4j-core
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.0.0
|
75
|
+
version: 5.0.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.0.0
|
82
|
+
version: 5.0.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: railties
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -307,12 +307,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
307
307
|
version: 1.9.3
|
308
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
309
309
|
requirements:
|
310
|
-
- - "
|
310
|
+
- - ">="
|
311
311
|
- !ruby/object:Gem::Version
|
312
|
-
version:
|
312
|
+
version: '0'
|
313
313
|
requirements: []
|
314
314
|
rubyforge_project: neo4j
|
315
|
-
rubygems_version: 2.4.
|
315
|
+
rubygems_version: 2.4.6
|
316
316
|
signing_key:
|
317
317
|
specification_version: 4
|
318
318
|
summary: A graph database for Ruby
|