neo4j 6.1.12 → 7.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -33
- data/lib/neo4j.rb +6 -10
- data/lib/neo4j/active_node.rb +1 -0
- data/lib/neo4j/active_node/enum.rb +29 -0
- data/lib/neo4j/active_node/has_n.rb +1 -1
- data/lib/neo4j/active_node/has_n/association.rb +1 -1
- data/lib/neo4j/active_node/labels.rb +16 -8
- data/lib/neo4j/active_node/persistence.rb +14 -6
- data/lib/neo4j/active_node/query/query_proxy.rb +20 -0
- data/lib/neo4j/active_node/query/query_proxy_find_in_batches.rb +1 -1
- data/lib/neo4j/active_node/query/query_proxy_methods.rb +21 -66
- data/lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb +83 -0
- data/lib/neo4j/active_node/query_methods.rb +2 -4
- data/lib/neo4j/active_node/scope.rb +5 -9
- data/lib/neo4j/active_rel.rb +2 -1
- data/lib/neo4j/active_rel/related_node.rb +2 -3
- data/lib/neo4j/errors.rb +19 -3
- data/lib/neo4j/railtie.rb +13 -0
- data/lib/neo4j/shared/attributes.rb +207 -0
- data/lib/neo4j/shared/declared_properties.rb +2 -8
- data/lib/neo4j/shared/declared_property.rb +40 -3
- data/lib/neo4j/shared/enum.rb +148 -0
- data/lib/neo4j/shared/filtered_hash.rb +1 -1
- data/lib/neo4j/shared/mass_assignment.rb +58 -0
- data/lib/neo4j/shared/property.rb +41 -45
- data/lib/neo4j/shared/type_converters.rb +76 -17
- data/lib/neo4j/shared/typecasted_attributes.rb +98 -0
- data/lib/neo4j/version.rb +1 -1
- data/neo4j.gemspec +0 -1
- metadata +10 -19
- data/lib/neo4j/shared/property/default_property.rb +0 -0
@@ -4,7 +4,13 @@ require 'bigdecimal/util'
|
|
4
4
|
require 'active_support/core_ext/big_decimal/conversions'
|
5
5
|
|
6
6
|
module Neo4j::Shared
|
7
|
+
class Boolean; end
|
8
|
+
|
7
9
|
module TypeConverters
|
10
|
+
CONVERTERS = {}
|
11
|
+
|
12
|
+
class Boolean; end
|
13
|
+
|
8
14
|
class BaseConverter
|
9
15
|
class << self
|
10
16
|
def converted?(value)
|
@@ -102,7 +108,7 @@ module Neo4j::Shared
|
|
102
108
|
end
|
103
109
|
|
104
110
|
def db_type
|
105
|
-
|
111
|
+
Neo4j::Shared::Boolean
|
106
112
|
end
|
107
113
|
|
108
114
|
alias_method :convert_type, :db_type
|
@@ -139,7 +145,7 @@ module Neo4j::Shared
|
|
139
145
|
end
|
140
146
|
|
141
147
|
def to_ruby(value)
|
142
|
-
Time.at(value).utc.to_date
|
148
|
+
value.respond_to?(:to_date) ? value.to_date : Time.at(value).utc.to_date
|
143
149
|
end
|
144
150
|
end
|
145
151
|
end
|
@@ -168,7 +174,10 @@ module Neo4j::Shared
|
|
168
174
|
|
169
175
|
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'
|
170
176
|
def to_ruby(value)
|
177
|
+
return value if value.is_a?(DateTime)
|
171
178
|
t = case value
|
179
|
+
when Time
|
180
|
+
return value.to_datetime.utc
|
172
181
|
when Integer
|
173
182
|
Time.at(value).utc
|
174
183
|
when String
|
@@ -211,7 +220,6 @@ module Neo4j::Shared
|
|
211
220
|
def to_ruby(value)
|
212
221
|
Time.at(value).utc
|
213
222
|
end
|
214
|
-
alias_method :call, :to_ruby
|
215
223
|
end
|
216
224
|
end
|
217
225
|
|
@@ -257,6 +265,47 @@ module Neo4j::Shared
|
|
257
265
|
end
|
258
266
|
end
|
259
267
|
|
268
|
+
class EnumConverter
|
269
|
+
def initialize(enum_keys)
|
270
|
+
@enum_keys = enum_keys
|
271
|
+
end
|
272
|
+
|
273
|
+
def converted?(value)
|
274
|
+
value.is_a?(db_type)
|
275
|
+
end
|
276
|
+
|
277
|
+
def db_type
|
278
|
+
Integer
|
279
|
+
end
|
280
|
+
|
281
|
+
def convert_type
|
282
|
+
Symbol
|
283
|
+
end
|
284
|
+
|
285
|
+
def to_ruby(value)
|
286
|
+
@enum_keys.key(value) unless value.nil?
|
287
|
+
end
|
288
|
+
|
289
|
+
alias_method :call, :to_ruby
|
290
|
+
|
291
|
+
def to_db(value)
|
292
|
+
@enum_keys[value.to_s.to_sym] || 0
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
class ObjectConverter < BaseConverter
|
297
|
+
class << self
|
298
|
+
def convert_type
|
299
|
+
Object
|
300
|
+
end
|
301
|
+
|
302
|
+
def to_ruby(value)
|
303
|
+
value
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
|
260
309
|
# Modifies a hash's values to be of types acceptable to Neo4j or matching what the user defined using `type` in property definitions.
|
261
310
|
# @param [Neo4j::Shared::Property] obj A node or rel that mixes in the Property module
|
262
311
|
# @param [Symbol] medium Indicates the type of conversion to perform.
|
@@ -277,11 +326,19 @@ module Neo4j::Shared
|
|
277
326
|
converted_property(primitive_type(key.to_sym), value, direction)
|
278
327
|
end
|
279
328
|
|
329
|
+
def typecaster_for(value)
|
330
|
+
Neo4j::Shared::TypeConverters.typecaster_for(value)
|
331
|
+
end
|
332
|
+
|
333
|
+
def typecast_attribute(typecaster, value)
|
334
|
+
Neo4j::Shared::TypeConverters.typecast_attribute(typecaster, value)
|
335
|
+
end
|
336
|
+
|
280
337
|
private
|
281
338
|
|
282
|
-
def converted_property(type, value,
|
339
|
+
def converted_property(type, value, direction)
|
283
340
|
return nil if value.nil?
|
284
|
-
TypeConverters
|
341
|
+
type.respond_to?(:db_type) || TypeConverters::CONVERTERS[type] ? TypeConverters.to_other(direction, value, type) : value
|
285
342
|
end
|
286
343
|
|
287
344
|
# If the attribute is to be typecast using a custom converter, which converter should it use? If no, returns the type to find a native serializer.
|
@@ -302,45 +359,47 @@ module Neo4j::Shared
|
|
302
359
|
end
|
303
360
|
|
304
361
|
class << self
|
305
|
-
attr_reader :converters
|
306
|
-
|
307
362
|
def included(_)
|
308
|
-
return if @converters
|
309
|
-
@converters = {}
|
310
363
|
Neo4j::Shared::TypeConverters.constants.each do |constant_name|
|
311
364
|
constant = Neo4j::Shared::TypeConverters.const_get(constant_name)
|
312
365
|
register_converter(constant) if constant.respond_to?(:convert_type)
|
313
366
|
end
|
314
367
|
end
|
315
368
|
|
369
|
+
def typecast_attribute(typecaster, value)
|
370
|
+
fail ArgumentError, "A typecaster must be given, #{typecaster} is invalid" unless typecaster.respond_to?(:to_ruby)
|
371
|
+
return value if value.nil?
|
372
|
+
typecaster.to_ruby(value)
|
373
|
+
end
|
374
|
+
|
316
375
|
def typecaster_for(primitive_type)
|
317
376
|
return nil if primitive_type.nil?
|
318
|
-
|
377
|
+
CONVERTERS[primitive_type]
|
319
378
|
end
|
320
379
|
|
321
380
|
# @param [Symbol] direction either :to_ruby or :to_other
|
322
381
|
def to_other(direction, value, type)
|
323
382
|
fail "Unknown direction given: #{direction}" unless direction == :to_ruby || direction == :to_db
|
324
|
-
found_converter =
|
383
|
+
found_converter = converter_for(type)
|
325
384
|
return value unless found_converter
|
326
385
|
return value if direction == :to_db && formatted_for_db?(found_converter, value)
|
327
386
|
found_converter.send(direction, value)
|
328
387
|
end
|
329
388
|
|
389
|
+
def converter_for(type)
|
390
|
+
type.respond_to?(:db_type) ? type : CONVERTERS[type]
|
391
|
+
end
|
392
|
+
|
330
393
|
# Attempts to determine whether conversion should be skipped because the object is already of the anticipated output type.
|
331
394
|
# @param [#convert_type] found_converter An object that responds to #convert_type, hinting that it is a type converter.
|
332
395
|
# @param value The value for conversion.
|
333
396
|
def formatted_for_db?(found_converter, value)
|
334
397
|
return false unless found_converter.respond_to?(:db_type)
|
335
|
-
|
336
|
-
found_converter.converted?(value)
|
337
|
-
else
|
338
|
-
value.is_a?(found_converter.db_type)
|
339
|
-
end
|
398
|
+
found_converter.respond_to?(:converted) ? found_converter.converted?(value) : value.is_a?(found_converter.db_type)
|
340
399
|
end
|
341
400
|
|
342
401
|
def register_converter(converter)
|
343
|
-
|
402
|
+
CONVERTERS[converter.convert_type] = converter
|
344
403
|
end
|
345
404
|
end
|
346
405
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Neo4j::Shared
|
2
|
+
# TypecastedAttributes allows types to be declared for your attributes
|
3
|
+
#
|
4
|
+
# Types are declared by passing the :type option to the attribute class
|
5
|
+
# method. After a type is declared, attribute readers will convert any
|
6
|
+
# assigned attribute value to the declared type. If the assigned value
|
7
|
+
# cannot be cast, nil will be returned instead. You can access the original
|
8
|
+
# assigned value using the before_type_cast methods.
|
9
|
+
#
|
10
|
+
# See {Typecasting} for the currently supported types.
|
11
|
+
#
|
12
|
+
# @example Usage
|
13
|
+
# class Person
|
14
|
+
# include Neo4j::Shared::TypecastedAttributes
|
15
|
+
# attribute :age, :type => Integer
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# person = Person.new
|
19
|
+
# person.age = "29"
|
20
|
+
# person.age #=> 29
|
21
|
+
# person.age_before_type_cast #=> "29"
|
22
|
+
#
|
23
|
+
# Originally part of ActiveAttr, https://github.com/cgriego/active_attr
|
24
|
+
module TypecastedAttributes
|
25
|
+
extend ActiveSupport::Concern
|
26
|
+
include Neo4j::Shared::Attributes
|
27
|
+
|
28
|
+
included do
|
29
|
+
attribute_method_suffix '_before_type_cast'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Read the raw attribute value
|
33
|
+
#
|
34
|
+
# @example Reading a raw age value
|
35
|
+
# person.age = "29"
|
36
|
+
# person.attribute_before_type_cast(:age) #=> "29"
|
37
|
+
#
|
38
|
+
# @param [String, Symbol, #to_s] name Attribute name
|
39
|
+
#
|
40
|
+
# @return [Object, nil] The attribute value before typecasting
|
41
|
+
def attribute_before_type_cast(name)
|
42
|
+
@attributes ||= {}
|
43
|
+
@attributes[name.to_s]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Reads the attribute and typecasts the result
|
49
|
+
def attribute(name)
|
50
|
+
typecast_attribute(_attribute_typecaster(name), super)
|
51
|
+
end
|
52
|
+
|
53
|
+
def typecast_attribute(typecaster, value)
|
54
|
+
self.class.typecast_attribute(typecaster, value)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Calculates an attribute type
|
58
|
+
#
|
59
|
+
# @private
|
60
|
+
def _attribute_type(attribute_name)
|
61
|
+
self.class._attribute_type(attribute_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Resolve an attribute typecaster
|
65
|
+
#
|
66
|
+
# @private
|
67
|
+
def _attribute_typecaster(attribute_name)
|
68
|
+
type = _attribute_type(attribute_name)
|
69
|
+
caster = self.class.attributes[attribute_name].typecaster || Neo4j::Shared::TypeConverters.typecaster_for(type)
|
70
|
+
caster || fail(Neo4j::UnknownTypeConverterError, "Unable to cast to type #{type}")
|
71
|
+
end
|
72
|
+
|
73
|
+
module ClassMethods
|
74
|
+
# Returns the class name plus its attribute names and types
|
75
|
+
#
|
76
|
+
# @example Inspect the model's definition.
|
77
|
+
# Person.inspect
|
78
|
+
#
|
79
|
+
# @return [String] Human-readable presentation of the attributes
|
80
|
+
def inspect
|
81
|
+
inspected_attributes = attribute_names.sort.map { |name| "#{name}: #{_attribute_type(name)}" }
|
82
|
+
attributes_list = "(#{inspected_attributes.join(', ')})" unless inspected_attributes.empty?
|
83
|
+
"#{name}#{attributes_list}"
|
84
|
+
end
|
85
|
+
|
86
|
+
# Calculates an attribute type
|
87
|
+
#
|
88
|
+
# @private
|
89
|
+
def _attribute_type(attribute_name)
|
90
|
+
attributes[attribute_name].type || Object
|
91
|
+
end
|
92
|
+
|
93
|
+
def typecast_attribute(typecaster, value)
|
94
|
+
Neo4j::Shared::TypeConverters.typecast_attribute(typecaster, value)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/neo4j/version.rb
CHANGED
data/neo4j.gemspec
CHANGED
@@ -29,7 +29,6 @@ A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks h
|
|
29
29
|
s.add_dependency('orm_adapter', '~> 0.5.0')
|
30
30
|
s.add_dependency('activemodel', '~> 4')
|
31
31
|
s.add_dependency('activesupport', '~> 4')
|
32
|
-
s.add_dependency('active_attr', '~> 0.8')
|
33
32
|
s.add_dependency('neo4j-core', '>= 6.0.0')
|
34
33
|
s.add_dependency('neo4j-community', '~> 2.0') if RUBY_PLATFORM =~ /java/
|
35
34
|
s.add_development_dependency('railties', '~> 4')
|
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:
|
4
|
+
version: 7.0.0.rc.1
|
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: 2016-
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orm_adapter
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: active_attr
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.8'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.8'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: neo4j-core
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,6 +215,7 @@ files:
|
|
229
215
|
- lib/neo4j/active_node/dependent.rb
|
230
216
|
- lib/neo4j/active_node/dependent/association_methods.rb
|
231
217
|
- lib/neo4j/active_node/dependent/query_proxy_methods.rb
|
218
|
+
- lib/neo4j/active_node/enum.rb
|
232
219
|
- lib/neo4j/active_node/has_n.rb
|
233
220
|
- lib/neo4j/active_node/has_n/association.rb
|
234
221
|
- lib/neo4j/active_node/has_n/association/rel_factory.rb
|
@@ -251,6 +238,7 @@ files:
|
|
251
238
|
- lib/neo4j/active_node/query/query_proxy_find_in_batches.rb
|
252
239
|
- lib/neo4j/active_node/query/query_proxy_link.rb
|
253
240
|
- lib/neo4j/active_node/query/query_proxy_methods.rb
|
241
|
+
- lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
|
254
242
|
- lib/neo4j/active_node/query_methods.rb
|
255
243
|
- lib/neo4j/active_node/reflection.rb
|
256
244
|
- lib/neo4j/active_node/rels.rb
|
@@ -277,22 +265,25 @@ files:
|
|
277
265
|
- lib/neo4j/railtie.rb
|
278
266
|
- lib/neo4j/schema/operation.rb
|
279
267
|
- lib/neo4j/shared.rb
|
268
|
+
- lib/neo4j/shared/attributes.rb
|
280
269
|
- lib/neo4j/shared/callbacks.rb
|
281
270
|
- lib/neo4j/shared/cypher.rb
|
282
271
|
- lib/neo4j/shared/declared_properties.rb
|
283
272
|
- lib/neo4j/shared/declared_property.rb
|
284
273
|
- lib/neo4j/shared/declared_property/index.rb
|
274
|
+
- lib/neo4j/shared/enum.rb
|
285
275
|
- lib/neo4j/shared/filtered_hash.rb
|
286
276
|
- lib/neo4j/shared/identity.rb
|
287
277
|
- lib/neo4j/shared/initialize.rb
|
288
278
|
- lib/neo4j/shared/marshal.rb
|
279
|
+
- lib/neo4j/shared/mass_assignment.rb
|
289
280
|
- lib/neo4j/shared/persistence.rb
|
290
281
|
- lib/neo4j/shared/property.rb
|
291
|
-
- lib/neo4j/shared/property/default_property.rb
|
292
282
|
- lib/neo4j/shared/query_factory.rb
|
293
283
|
- lib/neo4j/shared/rel_type_converters.rb
|
294
284
|
- lib/neo4j/shared/serialized_properties.rb
|
295
285
|
- lib/neo4j/shared/type_converters.rb
|
286
|
+
- lib/neo4j/shared/typecasted_attributes.rb
|
296
287
|
- lib/neo4j/shared/typecaster.rb
|
297
288
|
- lib/neo4j/shared/validations.rb
|
298
289
|
- lib/neo4j/tasks/migration.rake
|
@@ -328,9 +319,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
328
319
|
version: 1.9.3
|
329
320
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
330
321
|
requirements:
|
331
|
-
- - "
|
322
|
+
- - ">"
|
332
323
|
- !ruby/object:Gem::Version
|
333
|
-
version:
|
324
|
+
version: 1.3.1
|
334
325
|
requirements: []
|
335
326
|
rubyforge_project: neo4j
|
336
327
|
rubygems_version: 2.4.5.1
|
File without changes
|