neo4j 6.0.9 → 6.1.0
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 +11 -16
- data/Gemfile +6 -3
- data/README.md +1 -1
- data/lib/neo4j.rb +1 -0
- data/lib/neo4j/active_node.rb +3 -0
- data/lib/neo4j/active_node/has_n.rb +4 -3
- data/lib/neo4j/active_node/has_n/association.rb +22 -18
- data/lib/neo4j/active_node/persistence.rb +8 -0
- data/lib/neo4j/active_node/property.rb +1 -1
- data/lib/neo4j/active_node/query/query_proxy_find_in_batches.rb +1 -1
- data/lib/neo4j/active_rel.rb +3 -3
- data/lib/neo4j/active_rel/persistence.rb +8 -0
- data/lib/neo4j/active_rel/property.rb +14 -2
- data/lib/neo4j/active_rel/query.rb +1 -3
- data/lib/neo4j/class_arguments.rb +39 -0
- data/lib/neo4j/railtie.rb +2 -2
- data/lib/neo4j/shared.rb +0 -7
- data/lib/neo4j/shared/marshal.rb +23 -0
- data/lib/neo4j/shared/persistence.rb +36 -0
- data/lib/neo4j/shared/property.rb +8 -1
- data/lib/neo4j/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c832dc3c664a9c43d1014226af9d856a9ae5dc
|
4
|
+
data.tar.gz: 2343fc4c93707ee597da241d452da0b912a9f53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950118a98e2a592dd0a54550c9e47ed57e243a52e9c879404b0c1a539b1b63a0bfa8726711c107ea7af303aba750ff84846cd3508370b01dc410a282ba3cd731
|
7
|
+
data.tar.gz: d9c55f185d51bf226f98de8eac2fe52db9d1d64b1a79ec1822d7805ee04fd3539f3c13e666ec89961df3a4e3850e69fdb3f89ac40be6ee0285568a7f1fbc7894
|
data/CHANGELOG.md
CHANGED
@@ -3,29 +3,24 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
This file should follow the standards specified on [http://keepachangelog.com/]
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
-
## [6.0
|
6
|
+
## [6.1.0] - 2016-01-01
|
7
7
|
|
8
|
-
###
|
9
|
-
|
10
|
-
- Fix to `find_in_batches` (thanks to ProGM / see #1208)
|
11
|
-
|
12
|
-
## [6.0.8] - 03-14-2016
|
13
|
-
|
14
|
-
### Fixed
|
15
|
-
|
16
|
-
- Fixed issue where backticks weren't being added to where clauses for `with_associations`
|
8
|
+
### Changed
|
17
9
|
|
18
|
-
|
10
|
+
- When a `model_class` is specified on an association which is not an ActiveNode model, an error is raised
|
11
|
+
- The `model_class` option on associations can no longer be a `Class` constant (should be a String, Symbol, nil, false, or an Array of Symbols/Strings)
|
12
|
+
- The `rel_class` option on associations can no longer be a `Class` constant (should be a String, Symbol, or nil)
|
13
|
+
- The `from_class` and `to_class` arguments can no longer be a `Class` constant (should be a String, Symbol, :any, or false)
|
14
|
+
- ActiveNode and ActiveRel models can now be marshaled (thanks to jhoffner for the suggestion in #1093)
|
19
15
|
|
20
16
|
### Fixed
|
21
17
|
|
22
|
-
-
|
23
|
-
|
24
|
-
## [6.0.6] - 01-20-2016
|
18
|
+
- Inheritance of properties in ActiveRel is fixed (see #1080)
|
25
19
|
|
26
|
-
###
|
20
|
+
### Added
|
27
21
|
|
28
|
-
-
|
22
|
+
- `config/neo4j.yml` now renders with an ERB step (thanks to mrstif via #1060)
|
23
|
+
- `#increment`, `#increment!` and `#concurrent_increment!` methods added to instances of ActiveNode and ActiveRel (thanks to ProGM in #1074)
|
29
24
|
|
30
25
|
## [6.0.5] - 12-29-2015
|
31
26
|
|
data/Gemfile
CHANGED
@@ -2,8 +2,11 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
if ENV['CI']
|
6
|
+
gem 'neo4j-core', github: 'neo4jrb/neo4j-core', branch: 'master'
|
7
|
+
else
|
8
|
+
# gem 'neo4j-core', path: '../neo4j-core'
|
9
|
+
end
|
7
10
|
|
8
11
|
# gem 'active_attr', github: 'neo4jrb/active_attr', branch: 'performance'
|
9
12
|
# gem 'active_attr', path: '../active_attr'
|
@@ -13,7 +16,7 @@ group 'test' do
|
|
13
16
|
gem 'codecov', require: false
|
14
17
|
gem 'simplecov', require: false
|
15
18
|
gem 'simplecov-html', require: false
|
16
|
-
gem 'rspec', '~>
|
19
|
+
gem 'rspec', '~> 3.4'
|
17
20
|
gem 'its'
|
18
21
|
gem 'test-unit'
|
19
22
|
gem 'overcommit'
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ All new documentation will be done via our [readthedocs](http://neo4jrb.readthed
|
|
18
18
|
|
19
19
|
### Contact Us
|
20
20
|
|
21
|
-
[](http://stackoverflow.com/questions/ask?tags=neo4j.rb+neo4j+ruby) [](https://gitter.im/neo4jrb/neo4j?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://twitter.com/neo4jrb)
|
21
|
+
[](http://stackoverflow.com/questions/ask?tags=neo4j.rb+neo4j+ruby) [](https://gitter.im/neo4jrb/neo4j?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://twitter.com/neo4jrb)
|
22
22
|
|
23
23
|
|
24
24
|
|
data/lib/neo4j.rb
CHANGED
@@ -24,6 +24,7 @@ require 'neo4j/active_rel/rel_wrapper'
|
|
24
24
|
require 'neo4j/active_node/node_wrapper'
|
25
25
|
require 'neo4j/shared/type_converters'
|
26
26
|
require 'neo4j/shared/rel_type_converters'
|
27
|
+
require 'neo4j/shared/marshal'
|
27
28
|
require 'neo4j/type_converters'
|
28
29
|
require 'neo4j/paginated'
|
29
30
|
require 'neo4j/schema/operation'
|
data/lib/neo4j/active_node.rb
CHANGED
@@ -23,8 +23,11 @@ module Neo4j
|
|
23
23
|
module ActiveNode
|
24
24
|
extend ActiveSupport::Concern
|
25
25
|
|
26
|
+
MARSHAL_INSTANCE_VARIABLES = [:@attributes, :@_persisted_obj, :@default_property_value]
|
27
|
+
|
26
28
|
include Neo4j::Shared
|
27
29
|
include Neo4j::Shared::Identity
|
30
|
+
include Neo4j::Shared::Marshal
|
28
31
|
include Neo4j::ActiveNode::Initialize
|
29
32
|
include Neo4j::ActiveNode::IdProperty
|
30
33
|
include Neo4j::Shared::SerializedProperties
|
@@ -306,9 +306,9 @@ module Neo4j::ActiveNode
|
|
306
306
|
#
|
307
307
|
# Post.has_one :in, :author, type: :has_author, model_class: 'Person'
|
308
308
|
#
|
309
|
-
# *model_class*: The model class to which the association is referring. Can be
|
310
|
-
#
|
311
|
-
#
|
309
|
+
# *model_class*: The model class to which the association is referring. Can be a
|
310
|
+
# Symbol/String (or an ``Array`` of same) with the name of the `ActiveNode` class,
|
311
|
+
# `false` to specify any model, or nil to specify that it should be guessed.
|
312
312
|
#
|
313
313
|
# *rel_class*: The ``ActiveRel`` class to use for this association. Can be either a
|
314
314
|
# model object ``include`` ing ``ActiveRel`` or a Symbol/String (or an ``Array`` of same).
|
@@ -504,6 +504,7 @@ module Neo4j::ActiveNode
|
|
504
504
|
end
|
505
505
|
|
506
506
|
def build_association(macro, direction, name, options)
|
507
|
+
options[:model_class] = options[:model_class].name if options[:model_class] == self
|
507
508
|
Neo4j::ActiveNode::HasN::Association.new(macro, direction, name, options).tap do |association|
|
508
509
|
@associations ||= {}
|
509
510
|
@associations[name] = association
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/inflector/inflections'
|
2
|
+
require 'neo4j/class_arguments'
|
2
3
|
|
3
4
|
module Neo4j
|
4
5
|
module ActiveNode
|
@@ -32,7 +33,7 @@ module Neo4j
|
|
32
33
|
@pending_model_refresh = @target_classes_or_nil = nil
|
33
34
|
|
34
35
|
# Using #to_s on purpose here to take care of classes/strings/symbols
|
35
|
-
@model_class = @model_class.to_s
|
36
|
+
@model_class = ClassArguments.constantize_argument(@model_class.to_s) if @model_class
|
36
37
|
end
|
37
38
|
|
38
39
|
def queue_model_refresh!
|
@@ -67,7 +68,7 @@ module Neo4j
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def target_classes
|
70
|
-
|
71
|
+
ClassArguments.constantize_argument(target_class_names)
|
71
72
|
end
|
72
73
|
|
73
74
|
def target_classes_or_nil
|
@@ -78,12 +79,12 @@ module Neo4j
|
|
78
79
|
return if model_class == false
|
79
80
|
|
80
81
|
Array.new(target_classes).map do |target_class|
|
81
|
-
"#{name}
|
82
|
+
"#{name}:#{target_class.mapped_label_name}"
|
82
83
|
end.join(' OR ')
|
83
84
|
end
|
84
85
|
|
85
86
|
def discovered_model
|
86
|
-
|
87
|
+
target_classes.select do |constant|
|
87
88
|
constant.ancestors.include?(::Neo4j::ActiveNode)
|
88
89
|
end
|
89
90
|
end
|
@@ -91,17 +92,11 @@ module Neo4j
|
|
91
92
|
def target_class
|
92
93
|
return @target_class if @target_class
|
93
94
|
|
94
|
-
if target_class_names && target_class_names.size == 1
|
95
|
-
class_const = target_class_names[0].constantize
|
95
|
+
return if !(target_class_names && target_class_names.size == 1)
|
96
96
|
|
97
|
-
|
98
|
-
fail ArgumentError, "Invalid argument to `#{name}` association: `#{class_const.inspect}` is not an ActiveNode model"
|
99
|
-
end
|
97
|
+
class_const = ClassArguments.constantize_argument(target_class_names[0])
|
100
98
|
|
101
|
-
|
102
|
-
end
|
103
|
-
rescue NameError
|
104
|
-
raise ArgumentError, "Invalid argument to `#{name}` association: Could not find class `#{target_class_names[0]}`"
|
99
|
+
@target_class = class_const
|
105
100
|
end
|
106
101
|
|
107
102
|
def callback(type)
|
@@ -215,12 +210,12 @@ module Neo4j
|
|
215
210
|
VALID_ASSOCIATION_OPTION_KEYS = [:type, :origin, :model_class, :rel_class, :dependent, :before, :after, :unique]
|
216
211
|
|
217
212
|
def validate_association_options!(_association_name, options)
|
218
|
-
|
213
|
+
ClassArguments.validate_argument!(options[:model_class], 'model_class')
|
214
|
+
ClassArguments.validate_argument!(options[:rel_class], 'rel_class')
|
215
|
+
|
219
216
|
message = case
|
220
|
-
when
|
221
|
-
|
222
|
-
when type_keys.empty?
|
223
|
-
"The 'type' option must be specified( even if it is `nil`) or `origin`/`rel_class` must be specified"
|
217
|
+
when (message = type_keys_error_message(options.keys))
|
218
|
+
message
|
224
219
|
when (unknown_keys = options.keys - VALID_ASSOCIATION_OPTION_KEYS).size > 0
|
225
220
|
"Unknown option(s) specified: #{unknown_keys.join(', ')}"
|
226
221
|
end
|
@@ -228,6 +223,15 @@ module Neo4j
|
|
228
223
|
fail ArgumentError, message if message
|
229
224
|
end
|
230
225
|
|
226
|
+
def type_keys_error_message(keys)
|
227
|
+
type_keys = (keys & [:type, :origin, :rel_class])
|
228
|
+
if type_keys.size > 1
|
229
|
+
"Only one of 'type', 'origin', or 'rel_class' options are allowed for associations"
|
230
|
+
elsif type_keys.empty?
|
231
|
+
"The 'type' option must be specified( even if it is `nil`) or `origin`/`rel_class` must be specified"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
231
235
|
def check_valid_type_and_dir(type, direction)
|
232
236
|
fail ArgumentError, "Invalid association type: #{type.inspect} (valid value: :has_many and :has_one)" if ![:has_many, :has_one].include?(type.to_sym)
|
233
237
|
fail ArgumentError, "Invalid direction: #{direction.inspect} (valid value: :out, :in, and :both)" if ![:out, :in, :both].include?(direction.to_sym)
|
@@ -29,6 +29,14 @@ module Neo4j::ActiveNode
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
# Increments concurrently a numeric attribute by a centain amount
|
33
|
+
# @param [Symbol, String] name of the attribute to increment
|
34
|
+
# @param [Integer, Float] amount to increment
|
35
|
+
def concurrent_increment!(attribute, by = 1)
|
36
|
+
query_node = Neo4j::Session.query.match_nodes(n: neo_id)
|
37
|
+
increment_by_query! query_node, attribute, by
|
38
|
+
end
|
39
|
+
|
32
40
|
# Persist the object to the database. Validations and Callbacks are included
|
33
41
|
# by default but validation can be disabled by passing :validate => false
|
34
42
|
# to #save! Creates a new transaction.
|
@@ -51,7 +51,7 @@ module Neo4j::ActiveNode
|
|
51
51
|
id_property_name = self.class.id_property_name.to_s
|
52
52
|
|
53
53
|
attribute_pairs = attributes.except(id_property_name).sort.map do |key, value|
|
54
|
-
[key, (value.is_a?(String) && value.size > 100) ? value.dup
|
54
|
+
[key, (value.is_a?(String) && value.size > 100) ? value.dup.first(100) : value]
|
55
55
|
end
|
56
56
|
|
57
57
|
attribute_pairs.unshift([id_property_name, self.send(id_property_name)])
|
data/lib/neo4j/active_rel.rb
CHANGED
@@ -4,9 +4,12 @@ module Neo4j
|
|
4
4
|
module ActiveRel
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
MARSHAL_INSTANCE_VARIABLES = [:@attributes, :@rel_type, :@_persisted_obj]
|
8
|
+
|
7
9
|
include Neo4j::Shared
|
8
10
|
include Neo4j::ActiveRel::Initialize
|
9
11
|
include Neo4j::Shared::Identity
|
12
|
+
include Neo4j::Shared::Marshal
|
10
13
|
include Neo4j::Shared::SerializedProperties
|
11
14
|
include Neo4j::ActiveRel::Property
|
12
15
|
include Neo4j::ActiveRel::Persistence
|
@@ -40,9 +43,6 @@ module Neo4j
|
|
40
43
|
include Neo4j::Timestamps if Neo4j::Config[:record_timestamps]
|
41
44
|
|
42
45
|
def self.inherited(other)
|
43
|
-
attributes.each_pair do |k, v|
|
44
|
-
other.inherit_property k.to_sym, v.clone, declared_properties[k].options
|
45
|
-
end
|
46
46
|
super
|
47
47
|
end
|
48
48
|
end
|
@@ -36,6 +36,14 @@ module Neo4j::ActiveRel
|
|
36
36
|
save(*args) or fail(RelInvalidError, inspect) # rubocop:disable Style/AndOr
|
37
37
|
end
|
38
38
|
|
39
|
+
# Increments concurrently a numeric attribute by a centain amount
|
40
|
+
# @param [Symbol, String] name of the attribute to increment
|
41
|
+
# @param [Integer, Float] amount to increment
|
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
|
46
|
+
|
39
47
|
def create_model
|
40
48
|
validate_node_classes!
|
41
49
|
rel = _create_rel
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'neo4j/class_arguments'
|
2
|
+
|
1
3
|
module Neo4j::ActiveRel
|
2
4
|
module Property
|
3
5
|
extend ActiveSupport::Concern
|
@@ -55,13 +57,23 @@ module Neo4j::ActiveRel
|
|
55
57
|
|
56
58
|
%w(to_class from_class).each do |direction|
|
57
59
|
define_method("#{direction}") do |argument = nil|
|
58
|
-
|
59
|
-
|
60
|
+
if !argument.nil?
|
61
|
+
Neo4j::ClassArguments.validate_argument!(argument, direction)
|
62
|
+
|
63
|
+
instance_variable_set("@#{direction}", argument)
|
64
|
+
end
|
65
|
+
|
66
|
+
self.instance_variable_get("@#{direction}")
|
60
67
|
end
|
61
68
|
|
62
69
|
define_method("_#{direction}") { instance_variable_get "@#{direction}" }
|
63
70
|
end
|
64
71
|
|
72
|
+
def valid_class_argument?(class_argument)
|
73
|
+
[String, Symbol, FalseClass].include?(class_argument.class) ||
|
74
|
+
(class_argument.is_a?(Array) && class_argument.all? { |c| [String, Symbol].include?(c.class) })
|
75
|
+
end
|
76
|
+
|
65
77
|
alias_method :start_class, :from_class
|
66
78
|
alias_method :end_class, :to_class
|
67
79
|
|
@@ -73,9 +73,7 @@ module Neo4j::ActiveRel
|
|
73
73
|
|
74
74
|
def as_constant(given_class)
|
75
75
|
case given_class
|
76
|
-
when String
|
77
|
-
given_class.constantize
|
78
|
-
when Symbol
|
76
|
+
when String, Symbol
|
79
77
|
given_class.to_s.constantize
|
80
78
|
when Array
|
81
79
|
fail "ActiveRel query methods are being deprecated and do not support Array (from|to)_class options. Current value: #{given_class}"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module ClassArguments
|
3
|
+
class << self
|
4
|
+
INVALID_CLASS_ARGUMENT_ERROR = 'option must by String, Symbol, false, nil, or an Array of Symbols/Strings'
|
5
|
+
|
6
|
+
def valid_argument?(class_argument)
|
7
|
+
[NilClass, String, Symbol, FalseClass].include?(class_argument.class) ||
|
8
|
+
(class_argument.is_a?(Array) && class_argument.all? { |c| [Symbol, String].include?(c.class) })
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate_argument!(class_argument, context)
|
12
|
+
return if valid_argument?(class_argument)
|
13
|
+
|
14
|
+
fail ArgumentError, "#{context} #{INVALID_CLASS_ARGUMENT_ERROR} (was #{class_argument.inspect})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def active_node_model?(class_constant)
|
18
|
+
class_constant.included_modules.include?(Neo4j::ActiveNode)
|
19
|
+
end
|
20
|
+
|
21
|
+
def constantize_argument(class_argument)
|
22
|
+
case class_argument
|
23
|
+
when 'any', :any, false, nil
|
24
|
+
nil
|
25
|
+
when Array
|
26
|
+
class_argument.map(&method(:constantize_argument))
|
27
|
+
else
|
28
|
+
class_argument.to_s.constantize.tap do |class_constant|
|
29
|
+
if !active_node_model?(class_constant)
|
30
|
+
fail ArgumentError, "#{class_constant} is not an ActiveNode model"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue NameError
|
35
|
+
raise ArgumentError, "Could not find class: #{class_argument}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/neo4j/railtie.rb
CHANGED
@@ -30,7 +30,7 @@ module Neo4j
|
|
30
30
|
|
31
31
|
return if !cfg.sessions.empty?
|
32
32
|
|
33
|
-
cfg.sessions << {type: cfg.session_type, path: cfg.session_path, options: cfg.session_options}
|
33
|
+
cfg.sessions << {type: cfg.session_type, path: cfg.session_path, options: cfg.session_options.merge(default: true)}
|
34
34
|
end
|
35
35
|
|
36
36
|
def setup_config_defaults!(cfg)
|
@@ -42,7 +42,7 @@ module Neo4j
|
|
42
42
|
|
43
43
|
def config_data
|
44
44
|
@config_data ||= if yaml_path
|
45
|
-
HashWithIndifferentAccess.new(YAML.load(yaml_path.read)[Rails.env])
|
45
|
+
HashWithIndifferentAccess.new(YAML.load(ERB.new(yaml_path.read).result)[Rails.env])
|
46
46
|
else
|
47
47
|
{}
|
48
48
|
end
|
data/lib/neo4j/shared.rb
CHANGED
@@ -33,13 +33,6 @@ module Neo4j
|
|
33
33
|
def self.i18n_scope
|
34
34
|
:neo4j
|
35
35
|
end
|
36
|
-
|
37
|
-
def self.inherited(other)
|
38
|
-
attributes.each_pair do |k, v|
|
39
|
-
other.inherit_property k.to_sym, v.clone, declared_properties[k].options
|
40
|
-
end
|
41
|
-
super
|
42
|
-
end
|
43
36
|
end
|
44
37
|
|
45
38
|
def declared_properties
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Shared
|
3
|
+
module Marshal
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def marshal_dump
|
7
|
+
marshal_instance_variables.map(&method(:instance_variable_get))
|
8
|
+
end
|
9
|
+
|
10
|
+
def marshal_load(array)
|
11
|
+
marshal_instance_variables.zip(array).each do |var, value|
|
12
|
+
instance_variable_set(var, value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def marshal_instance_variables
|
19
|
+
self.class::MARSHAL_INSTANCE_VARIABLES
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -37,6 +37,29 @@ module Neo4j::Shared
|
|
37
37
|
props_for_db(changed_props)
|
38
38
|
end
|
39
39
|
|
40
|
+
# Increments a numeric attribute by a centain amount
|
41
|
+
# @param [Symbol, String] name of the attribute to increment
|
42
|
+
# @param [Integer, Float] amount to increment
|
43
|
+
def increment(attribute, by = 1)
|
44
|
+
self[attribute] ||= 0
|
45
|
+
self[attribute] += by
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Convenience method to increment numeric attribute and #save at the same time
|
50
|
+
# @param [Symbol, String] name of the attribute to increment
|
51
|
+
# @param [Integer, Float] amount to increment
|
52
|
+
def increment!(attribute, by = 1)
|
53
|
+
increment(attribute, by).update_attribute(attribute, self[attribute])
|
54
|
+
end
|
55
|
+
|
56
|
+
# Increments concurrently a numeric attribute by a centain amount
|
57
|
+
# @param [Symbol, String] name of the attribute to increment
|
58
|
+
# @param [Integer, Float] amount to increment
|
59
|
+
def concurrent_increment!(_attribute, _by = 1)
|
60
|
+
fail 'not_implemented'
|
61
|
+
end
|
62
|
+
|
40
63
|
# Convenience method to set attribute and #save at the same time
|
41
64
|
# @param [Symbol, String] attribute of the attribute to update
|
42
65
|
# @param [Object] value to set
|
@@ -166,6 +189,19 @@ module Neo4j::Shared
|
|
166
189
|
end
|
167
190
|
end
|
168
191
|
|
192
|
+
protected
|
193
|
+
|
194
|
+
def increment_by_query!(match_query, attribute, by, element_name = :n)
|
195
|
+
new_attribute = match_query.with(element_name)
|
196
|
+
.set("#{element_name}.`#{attribute}` = COALESCE(#{element_name}.`#{attribute}`, 0) + {by}")
|
197
|
+
.params(by: by).limit(1)
|
198
|
+
.pluck("#{element_name}.`#{attribute}`").first
|
199
|
+
return false unless new_attribute
|
200
|
+
self[attribute] = new_attribute
|
201
|
+
changed_attributes.delete(attribute)
|
202
|
+
true
|
203
|
+
end
|
204
|
+
|
169
205
|
private
|
170
206
|
|
171
207
|
def props_for_db(props_hash)
|
@@ -27,7 +27,7 @@ module Neo4j::Shared
|
|
27
27
|
# It calls an init method in active_attr that has a very negative impact on performance.
|
28
28
|
def initialize(attributes = nil)
|
29
29
|
attributes = process_attributes(attributes)
|
30
|
-
@relationship_props =
|
30
|
+
@relationship_props = self.class.extract_association_attributes!(attributes)
|
31
31
|
modded_attributes = inject_defaults!(attributes)
|
32
32
|
validate_attributes!(modded_attributes)
|
33
33
|
writer_method_props = extract_writer_methods!(modded_attributes)
|
@@ -132,6 +132,13 @@ module Neo4j::Shared
|
|
132
132
|
|
133
133
|
def_delegators :declared_properties, :serialized_properties, :serialized_properties=, :serialize, :declared_property_defaults
|
134
134
|
|
135
|
+
def inherited(other)
|
136
|
+
self.declared_properties.registered_properties.each_pair do |prop_key, prop_def|
|
137
|
+
other.property(prop_key, prop_def.options)
|
138
|
+
end
|
139
|
+
super
|
140
|
+
end
|
141
|
+
|
135
142
|
# Defines a property on the class
|
136
143
|
#
|
137
144
|
# See active_attr gem for allowed options, e.g which type
|
data/lib/neo4j/version.rb
CHANGED
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: 6.0
|
4
|
+
version: 6.1.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: 2016-
|
11
|
+
date: 2016-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orm_adapter
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/neo4j/active_rel/related_node.rb
|
269
269
|
- lib/neo4j/active_rel/types.rb
|
270
270
|
- lib/neo4j/active_rel/validations.rb
|
271
|
+
- lib/neo4j/class_arguments.rb
|
271
272
|
- lib/neo4j/config.rb
|
272
273
|
- lib/neo4j/core/query.rb
|
273
274
|
- lib/neo4j/errors.rb
|
@@ -284,6 +285,7 @@ files:
|
|
284
285
|
- lib/neo4j/shared/filtered_hash.rb
|
285
286
|
- lib/neo4j/shared/identity.rb
|
286
287
|
- lib/neo4j/shared/initialize.rb
|
288
|
+
- lib/neo4j/shared/marshal.rb
|
287
289
|
- lib/neo4j/shared/persistence.rb
|
288
290
|
- lib/neo4j/shared/property.rb
|
289
291
|
- lib/neo4j/shared/property/default_property.rb
|