active_record_compose 0.1.7 → 0.1.8

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: bff1c2fd72a225a89ada1c0cab86b6d32f31c0052d8857e665eb2796f4a40883
4
- data.tar.gz: 307e8ecf50282b9a19e224870796944de47d37f8802d0ffe63cca465eb663cc4
3
+ metadata.gz: b8e8c6c04b96e3396f6718d7bfbbf8867dce32cf34b9235ea2d37609c9e84dfb
4
+ data.tar.gz: c05ca6adb42a249a813ef250ea48fe05c72b073408bf3e5503acdb16df9cf585
5
5
  SHA512:
6
- metadata.gz: 12f503a644d60932a095a587e8152d37af25b8eccfb0cc5cd32dc5941eb896104880328ff6e3ed2b7fd53ee78fad9f7962e23b5ffc1070bbaa00518e482dccf4
7
- data.tar.gz: 91d912f794a250e44e8ad5fea2694f00a52eb98df3f217364e8eb637a6971692998526e86c2d908dc28ce7b0ff99ada394ca287b39342714377af63a1869c4be
6
+ metadata.gz: 2c3e646ab33c317647fa533e6d652e9b28fe442d337385d9505f2adafc65aaa75a7c3e6fad86cf869f3842b6c5ac8eebc05690e12547c76ccacdc3c08ca8c4e8
7
+ data.tar.gz: 1dcaf9de91f6b59a41c7848c969880290c5cb5288e1abba45de07a41b030d3f3d2e6312eca37ac120556d9233b62184a11d410ce208202adf56c9cc00e74acdf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.8] - 2024-01-16
4
+
5
+ - avoid executing `#save!` from `Model#save`
6
+ - on save, ignore nil elements from models.
7
+
3
8
  ## [0.1.7] - 2024-01-15
4
9
 
5
10
  - remove `add_development_dependency` from gemspec
@@ -73,7 +73,7 @@ module ActiveRecordCompose
73
73
  def __each_by_wrapped
74
74
  return enum_for(:__each_by_wrapped) unless block_given?
75
75
 
76
- models.each { yield _1 }
76
+ models.each { yield _1 if _1.__raw_model }
77
77
  self
78
78
  end
79
79
 
@@ -31,7 +31,7 @@ module ActiveRecordCompose
31
31
  def save
32
32
  return false if invalid?
33
33
 
34
- save_in_transaction { save_models }
34
+ save_in_transaction { save_models(bang: false) }
35
35
  end
36
36
 
37
37
  # Save the models that exist in models.
@@ -42,7 +42,7 @@ module ActiveRecordCompose
42
42
  def save!
43
43
  valid? || raise_validation_error
44
44
 
45
- save_in_transaction { save_models } || raise_on_save_error
45
+ save_in_transaction { save_models(bang: true) } || raise_on_save_error
46
46
  end
47
47
 
48
48
  # Behavior is same to `#save`, but `before_create` and `after_create` hooks fires.
@@ -74,7 +74,7 @@ module ActiveRecordCompose
74
74
  assign_attributes(attributes)
75
75
  return false if invalid?
76
76
 
77
- save_in_transaction { run_callbacks(:create) { save_models } }
77
+ save_in_transaction { run_callbacks(:create) { save_models(bang: false) } }
78
78
  end
79
79
 
80
80
  # Behavior is same to `#create`, but raises an exception prematurely on failure.
@@ -83,7 +83,7 @@ module ActiveRecordCompose
83
83
  assign_attributes(attributes)
84
84
  valid? || raise_validation_error
85
85
 
86
- save_in_transaction { run_callbacks(:create) { save_models } } || raise_on_save_error
86
+ save_in_transaction { run_callbacks(:create) { save_models(bang: true) } } || raise_on_save_error
87
87
  end
88
88
 
89
89
  # Behavior is same to `#save`, but `before_update` and `after_update` hooks fires.
@@ -115,7 +115,7 @@ module ActiveRecordCompose
115
115
  assign_attributes(attributes)
116
116
  return false if invalid?
117
117
 
118
- save_in_transaction { run_callbacks(:update) { save_models } }
118
+ save_in_transaction { run_callbacks(:update) { save_models(bang: false) } }
119
119
  end
120
120
 
121
121
  # Behavior is same to `#update`, but raises an exception prematurely on failure.
@@ -124,7 +124,7 @@ module ActiveRecordCompose
124
124
  assign_attributes(attributes)
125
125
  valid? || raise_validation_error
126
126
 
127
- save_in_transaction { run_callbacks(:update) { save_models } } || raise_on_save_error
127
+ save_in_transaction { run_callbacks(:update) { save_models(bang: true) } } || raise_on_save_error
128
128
  end
129
129
 
130
130
  private
@@ -135,10 +135,10 @@ module ActiveRecordCompose
135
135
 
136
136
  def validate_models = wrapped_models.select { _1.invalid? }.each { errors.merge!(_1) }
137
137
 
138
- def save_in_transaction(&block)
138
+ def save_in_transaction(...)
139
139
  run_callbacks(:commit) do
140
140
  result = ::ActiveRecord::Base.transaction do
141
- raise ActiveRecord::Rollback unless run_callbacks(:save, &block)
141
+ raise ActiveRecord::Rollback unless run_callbacks(:save, ...)
142
142
 
143
143
  true
144
144
  end
@@ -149,7 +149,7 @@ module ActiveRecordCompose
149
149
  end.present?
150
150
  end
151
151
 
152
- def save_models = wrapped_models.all? { _1.save! }
152
+ def save_models(bang:) = wrapped_models.all? { bang ? _1.save! : _1.save }
153
153
 
154
154
  def raise_validation_error = raise ActiveRecord::RecordInvalid, self
155
155
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordCompose
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
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.7
4
+ version: 0.1.8
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-14 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -51,7 +51,7 @@ metadata:
51
51
  homepage_uri: https://github.com/hamajyotan/active_record_compose
52
52
  source_code_uri: https://github.com/hamajyotan/active_record_compose
53
53
  changelog_uri: https://github.com/hamajyotan/active_record_compose/blob/main/CHANGELOG.md
54
- documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.1.7
54
+ documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.1.8
55
55
  rubygems_mfa_required: 'true'
56
56
  post_install_message:
57
57
  rdoc_options: []