activecypher 0.10.0 → 0.10.3
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/lib/active_cypher/relationship.rb +29 -7
- data/lib/active_cypher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3040943b0361f537dd3f6a68320463195607e72001f6e25b340d81212cd7a13a
|
4
|
+
data.tar.gz: 6d35f5d0e9c21d9e695ab898896f047fa36ab2aa8d08f997b8ad67e4a5ae0cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dddf85e77779795ecc95dd81834c0b4c13213ece522e019f50345f4ca1bd0944241e58ce0d4dfcbaa97f3e9b951cc44dc311d41b17bdf25578ca8f43e9bc5155
|
7
|
+
data.tar.gz: 74d562c623379a836dc1166a7fa3caf7d94743b728bba1f1f84acc3377d59f2278147cbb874c013981c0652cd360f49a11f7fc738f28cc635e2ecb9cbfc8d360
|
@@ -39,6 +39,7 @@ module ActiveCypher
|
|
39
39
|
include ActiveModel::Attributes
|
40
40
|
include ActiveModel::Dirty
|
41
41
|
include ActiveModel::Naming
|
42
|
+
include ActiveModel::Validations
|
42
43
|
|
43
44
|
include Model::ConnectionOwner
|
44
45
|
include Logging
|
@@ -155,14 +156,14 @@ module ActiveCypher
|
|
155
156
|
|
156
157
|
# -- factories -----------------------------------------------
|
157
158
|
# Mirrors ActiveRecord.create
|
158
|
-
def create(attrs = {}, from_node:, to_node
|
159
|
-
new(attrs, from_node: from_node, to_node: to_node).tap(&:save)
|
159
|
+
def create(attrs = {}, from_node:, to_node:, **attribute_kwargs)
|
160
|
+
new(attrs, from_node: from_node, to_node: to_node, **attribute_kwargs).tap(&:save)
|
160
161
|
end
|
161
162
|
|
162
163
|
# Bang version of create - raises exception if save fails
|
163
164
|
# For when you want your relationship failures to be as dramatic as your breakups
|
164
|
-
def create!(attrs = {}, from_node:, to_node
|
165
|
-
relationship = create(attrs, from_node: from_node, to_node: to_node)
|
165
|
+
def create!(attrs = {}, from_node:, to_node:, **attribute_kwargs)
|
166
|
+
relationship = create(attrs, from_node: from_node, to_node: to_node, **attribute_kwargs)
|
166
167
|
if relationship.persisted?
|
167
168
|
relationship
|
168
169
|
else
|
@@ -267,10 +268,15 @@ module ActiveCypher
|
|
267
268
|
attr_accessor :from_node, :to_node
|
268
269
|
attr_reader :new_record
|
269
270
|
|
270
|
-
def initialize(attrs = {}, from_node: nil, to_node: nil)
|
271
|
+
def initialize(attrs = {}, from_node: nil, to_node: nil, **attribute_kwargs)
|
271
272
|
_run(:initialize) do
|
272
273
|
super()
|
273
|
-
|
274
|
+
|
275
|
+
# Merge explicit attrs hash with keyword arguments for attributes.
|
276
|
+
# Note: `attribute_kwargs` takes precedence over `attrs` for keys that exist in both.
|
277
|
+
combined_attrs = attrs.merge(attribute_kwargs)
|
278
|
+
assign_attributes(combined_attrs) if combined_attrs.any?
|
279
|
+
|
274
280
|
@from_node = from_node
|
275
281
|
@to_node = to_node
|
276
282
|
@new_record = true
|
@@ -285,7 +291,9 @@ module ActiveCypher
|
|
285
291
|
# --------------------------------------------------------------
|
286
292
|
# Persistence API
|
287
293
|
# --------------------------------------------------------------
|
288
|
-
def save
|
294
|
+
def save(validate: true)
|
295
|
+
return false if validate && !valid?
|
296
|
+
|
289
297
|
_run(:save) do
|
290
298
|
if new_record?
|
291
299
|
_run(:create) { create_relationship }
|
@@ -298,6 +306,20 @@ module ActiveCypher
|
|
298
306
|
false
|
299
307
|
end
|
300
308
|
|
309
|
+
# Bang version of save - raises exception if save fails
|
310
|
+
# For when you want your relationship persistence to be as dramatic as your code reviews
|
311
|
+
def save!
|
312
|
+
if save
|
313
|
+
self
|
314
|
+
else
|
315
|
+
error_msgs = errors.full_messages.join(', ')
|
316
|
+
error_msgs = 'Validation failed' if error_msgs.empty?
|
317
|
+
raise ActiveCypher::RecordNotSaved,
|
318
|
+
"#{self.class} could not be saved: #{error_msgs}. " \
|
319
|
+
'Perhaps this relationship was never meant to be?'
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
301
323
|
def destroy
|
302
324
|
_run(:destroy) do
|
303
325
|
raise 'Cannot destroy a new relationship' if new_record?
|