active_record_compose 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1638c67c9c0cebca26544e01db7b210a0bde69d581471d3fbe771ada25c124b9
4
- data.tar.gz: d7c43f6b81793f349a2f4e33132616b8dca2971a607d49ecedaa102fed1b1f5f
3
+ metadata.gz: dd2ae31a400b17c7ab14c90bd1440060676590c23f91a61f7f54e9a7decf0294
4
+ data.tar.gz: 4a599ee2da8a5dcc3b0d9279a360b611b2e38f72304e8a837271f01e2b9821b2
5
5
  SHA512:
6
- metadata.gz: 9b9aca1764d28fdeb52b0d32fdc6fb0ca13e6c1891efd47335f18660935b36ae64be28cb1a6db08bf1b8b0d3d65aa9daa94bccdea03982112fd59386e57e7e50
7
- data.tar.gz: 6888e57191546c7d698bde1f2741f280b930d8b8f1f648c02ec0cd025d54a8f89d88bb4dd1cbe0feaf0e37e5f1fd8d4885032259481536edcd73aad1d067aed8
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordCompose
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
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.5
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 00:00:00.000000000 Z
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.5
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: []