active_record_compose 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f0306635ed35d2888c6a8f5ddc3d0ac5b04ba6aee2a2f6eaba304e57bc05ebc
4
- data.tar.gz: 3fdd952bc0c2b93a448f2be8b8d9a441afb20d635eab9a32ed05b6a837978d7e
3
+ metadata.gz: 1638c67c9c0cebca26544e01db7b210a0bde69d581471d3fbe771ada25c124b9
4
+ data.tar.gz: d7c43f6b81793f349a2f4e33132616b8dca2971a607d49ecedaa102fed1b1f5f
5
5
  SHA512:
6
- metadata.gz: cd5b513cfe39716ea5caf87be10e5fa9e514d134bed93b54456ce8bdf071a9ec5d336efbef8f609c4d3857e3763e4ed75b757db3145ca3cf4c7e79b6c98d6826
7
- data.tar.gz: 5e92989ed498e4e244692031231ad2f3c738025a1d066f2146f4ac36b37107143c46d131a30d7fb84df22ac703d230c9062446b5049a60012dd3209fdabe5e88
6
+ metadata.gz: 9b9aca1764d28fdeb52b0d32fdc6fb0ca13e6c1891efd47335f18660935b36ae64be28cb1a6db08bf1b8b0d3d65aa9daa94bccdea03982112fd59386e57e7e50
7
+ data.tar.gz: 6888e57191546c7d698bde1f2741f280b930d8b8f1f648c02ec0cd025d54a8f89d88bb4dd1cbe0feaf0e37e5f1fd8d4885032259481536edcd73aad1d067aed8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2024-01-11
4
+
5
+ - when invalid, raises ActiveRecord::RecordInvalid on #save!
6
+
3
7
  ## [0.1.4] - 2024-01-10
4
8
 
5
9
  - remove uniquely defined exception class.
@@ -28,7 +28,11 @@ module ActiveRecordCompose
28
28
  save_in_transaction { run_callbacks(:save) { save_models } }
29
29
  end
30
30
 
31
- def save! = save || raise_on_save_error
31
+ def save!
32
+ valid? || raise_validation_error
33
+
34
+ save_in_transaction { run_callbacks(:save) { save_models } } || raise_on_save_error
35
+ end
32
36
 
33
37
  # Behavior is same to `#save`, but `before_create` and `after_create` hooks fires.
34
38
  #
@@ -65,7 +69,10 @@ module ActiveRecordCompose
65
69
  # Behavior is same to `#create`, but raises an exception prematurely on failure.
66
70
  #
67
71
  def create!(attributes = {})
68
- create(attributes) || raise_on_save_error
72
+ assign_attributes(attributes)
73
+ valid? || raise_validation_error
74
+
75
+ save_in_transaction { run_callbacks(:save) { run_callbacks(:create) { save_models } } } || raise_on_save_error
69
76
  end
70
77
 
71
78
  # Behavior is same to `#save`, but `before_update` and `after_update` hooks fires.
@@ -103,7 +110,10 @@ module ActiveRecordCompose
103
110
  # Behavior is same to `#update`, but raises an exception prematurely on failure.
104
111
  #
105
112
  def update!(attributes = {})
106
- update(attributes) || raise_on_save_error
113
+ assign_attributes(attributes)
114
+ valid? || raise_validation_error
115
+
116
+ save_in_transaction { run_callbacks(:save) { run_callbacks(:update) { save_models } } } || raise_on_save_error
107
117
  end
108
118
 
109
119
  private
@@ -130,6 +140,8 @@ module ActiveRecordCompose
130
140
 
131
141
  def save_models = wrapped_models.all? { _1.save! }
132
142
 
143
+ def raise_validation_error = raise ActiveRecord::RecordInvalid, self
144
+
133
145
  def raise_on_save_error = raise ActiveRecord::RecordNotSaved.new('Failed to save the model.', self)
134
146
  end
135
147
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordCompose
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
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.4
4
+ version: 0.1.5
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-09 00:00:00.000000000 Z
11
+ date: 2024-01-11 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.4
68
+ documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.1.5
69
69
  rubygems_mfa_required: 'true'
70
70
  post_install_message:
71
71
  rdoc_options: []