active_record_compose 0.1.5 → 0.1.6
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 +6 -0
- data/lib/active_record_compose/inner_model.rb +17 -0
- data/lib/active_record_compose/model.rb +11 -0
- data/lib/active_record_compose/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd2ae31a400b17c7ab14c90bd1440060676590c23f91a61f7f54e9a7decf0294
|
4
|
+
data.tar.gz: 4a599ee2da8a5dcc3b0d9279a360b611b2e38f72304e8a837271f01e2b9821b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f3632810ffc48ed4bd10f78c4e54ff3c383d34231289f9639e488f270bbfd623a5f002b9f4afc653762611621c6f96b85b52498c2ba34e942d0c7c7288bfe4
|
7
|
+
data.tar.gz: 45fc861a9d223da11b841800dbc0ab689160cabdfdfda3a69433cb1d98884f76f30c742319ffc1ad3601527e9464b322456e44b73c6f098355f898909b5e340c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.6] - 2024-01-14
|
4
|
+
|
5
|
+
- add doc for `#save` and `#save!`.
|
6
|
+
- implement `#save` for symmetry with `#save!`
|
7
|
+
- add `InnerModel#initialize` doc.
|
8
|
+
|
3
9
|
## [0.1.5] - 2024-01-11
|
4
10
|
|
5
11
|
- when invalid, raises ActiveRecord::RecordInvalid on #save!
|
@@ -6,6 +6,7 @@ module ActiveRecordCompose
|
|
6
6
|
class InnerModel
|
7
7
|
# @param model [Object] the model instance.
|
8
8
|
# @param context [Symbol] :save or :destroy
|
9
|
+
# @param context [Proc] proc returning either :save or :destroy
|
9
10
|
def initialize(model, context: :save)
|
10
11
|
@model = model
|
11
12
|
@context = context
|
@@ -19,6 +20,22 @@ module ActiveRecordCompose
|
|
19
20
|
ret.presence_in(%i[save destroy]) || :save
|
20
21
|
end
|
21
22
|
|
23
|
+
# Execute save or destroy. Returns true on success, false on failure.
|
24
|
+
# Whether save or destroy is executed depends on the value of context.
|
25
|
+
#
|
26
|
+
# @return [Boolean] returns true on success, false on failure.
|
27
|
+
def save
|
28
|
+
case context
|
29
|
+
when :destroy
|
30
|
+
model.destroy
|
31
|
+
else
|
32
|
+
model.save
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Execute save or destroy. Unlike #save, an exception is raises on failure.
|
37
|
+
# Whether save or destroy is executed depends on the value of context.
|
38
|
+
#
|
22
39
|
# @return [InnerModel] self
|
23
40
|
def save!
|
24
41
|
case context
|
@@ -22,12 +22,23 @@ module ActiveRecordCompose
|
|
22
22
|
super(attributes)
|
23
23
|
end
|
24
24
|
|
25
|
+
# Save the models that exist in models.
|
26
|
+
# Returns false if any of the targets fail, true if all succeed.
|
27
|
+
#
|
28
|
+
# The save is performed within a single transaction.
|
29
|
+
#
|
30
|
+
# @return [Boolean] returns true on success, false on failure.
|
25
31
|
def save
|
26
32
|
return false if invalid?
|
27
33
|
|
28
34
|
save_in_transaction { run_callbacks(:save) { save_models } }
|
29
35
|
end
|
30
36
|
|
37
|
+
# Save the models that exist in models.
|
38
|
+
# Unlike #save, an exception is raises on failure.
|
39
|
+
#
|
40
|
+
# Saving, like `#save`, is performed within a single transaction.
|
41
|
+
#
|
31
42
|
def save!
|
32
43
|
valid? || raise_validation_error
|
33
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hamajyotan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -65,7 +65,7 @@ metadata:
|
|
65
65
|
homepage_uri: https://github.com/hamajyotan/active_record_compose
|
66
66
|
source_code_uri: https://github.com/hamajyotan/active_record_compose
|
67
67
|
changelog_uri: https://github.com/hamajyotan/active_record_compose/blob/main/CHANGELOG.md
|
68
|
-
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.1.
|
68
|
+
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.1.6
|
69
69
|
rubygems_mfa_required: 'true'
|
70
70
|
post_install_message:
|
71
71
|
rdoc_options: []
|