activeinteractor 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8990e7455e8d135a08b562e71a81bc6ca0e14b4b98f25505d73c6b02e2638466
4
- data.tar.gz: cf16acdae03eb8a3d15808fd4a01a112143878e502c20dd3a9d4dfc6396ebc09
3
+ metadata.gz: eb4ea1ab1b182695f3eb1123b9a2d24dc417a7b9c677cd4cfcd09e5c382c2353
4
+ data.tar.gz: 7cccf0b3d2d91598546c9683a10f7610b3c01941ea4c4aa9a6fe283dec673203
5
5
  SHA512:
6
- metadata.gz: ed677499ed9140e3dffedcee26f77f3b2967b51d24b7eabf594cacbfb1bf0f3a1bb9bd76f6a94a1a5d0ac61dd190380871391b76fc1afa29f65ae44fa57c1a75
7
- data.tar.gz: 874df56e5d15a5bcdda48c4297c5b5b64feed016d9c0ea84ac450b907569d49f8298e1b1d49929cac7e949522c31f94ef7a5f64426b5ad4ffbc70e1a2ccddb14
6
+ metadata.gz: 10f396ce895b5217010e39cd45354dba784b7216fd20aba7bb80acac9293e22711dfada8c6a573dbb8676ca961146b18bf1c215c73efdd3c351abc749c44b39a
7
+ data.tar.gz: fa3b9aa5f0d3b1629300003711264fd2fd61368268e579d57087592c87ed024eb46396fc316f2e5e1edf3e4043abb1c51a84334f0c645c450c80f9fda057be92
data/CHANGELOG.md CHANGED
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [v0.1.6] - 2019-07-24
11
+
12
+ ### Changed
13
+
14
+ - [#45] Lowered method complexity and enforced single responsibility
15
+
16
+ ### Security
17
+
18
+ - [#48] Update simplecov: 0.16.1 → 0.17.0 (major)
19
+ - [#51] Update rake: 12.3.2 → 12.3.3 (patch)
20
+
10
21
  ## [v0.1.5] - 2019-06-30
11
22
 
12
23
  ### Added
@@ -57,7 +68,8 @@ and this project adheres to [Semantic Versioning].
57
68
 
58
69
  <!-- versions -->
59
70
 
60
- [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.5..HEAD
71
+ [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.6..HEAD
72
+ [v0.1.6]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.5...v0.1.6
61
73
  [v0.1.5]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.4...v0.1.5
62
74
  [v0.1.4]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.3...v0.1.4
63
75
  [v0.1.3]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.2...v0.1.3
@@ -76,3 +88,6 @@ and this project adheres to [Semantic Versioning].
76
88
  [#37]: https://github.com/aaronmallen/activeinteractor/pull/37
77
89
  [#38]: https://github.com/aaronmallen/activeinteractor/pull/38
78
90
  [#39]: https://github.com/aaronmallen/activeinteractor/pull/39
91
+ [#45]: https://github.com/aaronmallen/activeinteractor/pull/45
92
+ [#48]: https://github.com/aaronmallen/activeinteractor/pull/48
93
+ [#51]: https://github.com/aaronmallen/activeinteractor/pull/51
@@ -55,9 +55,9 @@ module ActiveInteractor
55
55
  # @see https://api.rubyonrails.org/classes/ActiveModel/Errors.html ActiveModel::Errors
56
56
  # @raise [Error::ContextFailure]
57
57
  def fail!(errors = {})
58
- self.errors.merge!(errors) unless errors.empty?
59
- @_failed = true
60
- raise Error::ContextFailure, self
58
+ merge_errors(errors)
59
+ mark_failed!
60
+ raise_context_failure!
61
61
  end
62
62
 
63
63
  # Whether the context instance has failed. By default, a new
@@ -121,8 +121,8 @@ module ActiveInteractor
121
121
  def rollback!
122
122
  return false if @_rolled_back
123
123
 
124
- _called.reverse_each(&:execute_rollback)
125
- @_rolled_back = true
124
+ rollback_called
125
+ mark_rolledback!
126
126
  end
127
127
 
128
128
  # Whether the context instance is successful. By default, a new
@@ -162,6 +162,26 @@ module ActiveInteractor
162
162
  @_called ||= []
163
163
  end
164
164
 
165
+ def mark_failed!
166
+ @_failed = true
167
+ end
168
+
169
+ def mark_rolledback!
170
+ @_rolled_back = true
171
+ end
172
+
173
+ def merge_errors(errors)
174
+ self.errors.merge!(errors) unless errors.empty?
175
+ end
176
+
177
+ def raise_context_failure!
178
+ raise Error::ContextFailure, self
179
+ end
180
+
181
+ def rollback_called
182
+ _called.reverse_each(&:execute_rollback)
183
+ end
184
+
165
185
  def validation_callback?(method_name)
166
186
  _validate_callbacks.map(&:filter).include?(method_name)
167
187
  end
@@ -136,14 +136,9 @@ module ActiveInteractor
136
136
  #
137
137
  # @return [Hash{Symbol => *}] the deleted attributes
138
138
  def clean!
139
- deleted = {}
140
- return deleted if keys.empty?
139
+ return {} if keys.empty?
141
140
 
142
- keys.reject { |key| self.class.attributes.include?(key) }.each do |attribute|
143
- deleted[attribute] = self[attribute] if self[attribute]
144
- delete_field(key.to_s)
145
- end
146
- deleted
141
+ clean_keys!
147
142
  end
148
143
 
149
144
  # All keys of properties currently defined on the instance
@@ -172,6 +167,13 @@ module ActiveInteractor
172
167
  key
173
168
  end
174
169
 
170
+ def clean_keys!
171
+ keys.reject { |key| self.class.attributes.include?(key) }.each_with_object({}) do |attribute, deleted|
172
+ deleted[attribute] = self[attribute] if self[attribute]
173
+ delete_field(key.to_s)
174
+ end
175
+ end
176
+
175
177
  def map_attributes(attributes)
176
178
  return {} unless attributes
177
179
 
@@ -23,7 +23,7 @@ module ActiveInteractor
23
23
  def execute_perform
24
24
  execute_perform!
25
25
  rescue ActiveInteractor::Error::ContextFailure => e
26
- ActiveInteractor.logger.error("ActiveInteractor: #{e}")
26
+ log_context_failure(e)
27
27
  context
28
28
  end
29
29
 
@@ -32,12 +32,9 @@ module ActiveInteractor
32
32
  # @return [ActiveInteractor::Context::Base] an instance of {ActiveInteractor::Context::Base}
33
33
  def execute_perform!
34
34
  run_callbacks :perform do
35
- perform!
36
- finalize_context!
37
- context
38
- rescue # rubocop:disable Style/RescueStandardError
39
- context.rollback!
40
- raise
35
+ execute_context!
36
+ rescue => e # rubocop:disable Style/RescueStandardError
37
+ rollback_context_and_raise!(e)
41
38
  end
42
39
  end
43
40
 
@@ -64,6 +61,12 @@ module ActiveInteractor
64
61
  interactor.send(:context)
65
62
  end
66
63
 
64
+ def execute_context!
65
+ perform!
66
+ finalize_context!
67
+ context
68
+ end
69
+
67
70
  def fail_on_invalid_context!(validation_context = nil)
68
71
  context.fail! if should_fail_on_invalid_context?(validation_context)
69
72
  end
@@ -73,12 +76,21 @@ module ActiveInteractor
73
76
  context.called!
74
77
  end
75
78
 
79
+ def log_context_failure(exception)
80
+ ActiveInteractor.logger.error("ActiveInteractor: #{exception}")
81
+ end
82
+
76
83
  def perform!
77
84
  fail_on_invalid_context!(:calling)
78
85
  interactor.perform
79
86
  fail_on_invalid_context!(:called)
80
87
  end
81
88
 
89
+ def rollback_context_and_raise!(exception)
90
+ context.rollback!
91
+ raise exception
92
+ end
93
+
82
94
  def should_fail_on_invalid_context?(validation_context)
83
95
  !validate_context(validation_context) && interactor.fail_on_invalid_context?
84
96
  end
@@ -170,11 +170,21 @@ module ActiveInteractor
170
170
  # in favor of this default implementation.
171
171
  def perform
172
172
  self.class.organized.each do |interactor|
173
- run_callbacks :each_perform do
174
- self.context = interactor.new(context)
175
- .tap(&:skip_clean_context!)
176
- .execute_perform!
177
- end
173
+ execute_interactor_perform_with_callbacks!(interactor)
174
+ end
175
+ end
176
+
177
+ private
178
+
179
+ def execute_interactor_perform!(interactor)
180
+ self.context = interactor.new(context)
181
+ .tap(&:skip_clean_context!)
182
+ .execute_perform!
183
+ end
184
+
185
+ def execute_interactor_perform_with_callbacks!(interactor)
186
+ run_callbacks :each_perform do
187
+ execute_interactor_perform!(interactor)
178
188
  end
179
189
  end
180
190
  end
@@ -3,5 +3,5 @@
3
3
  module ActiveInteractor
4
4
  # The ActiveInteractor gem version
5
5
  # @return [String] the gem version
6
- VERSION = '0.1.5'
6
+ VERSION = '0.1.6'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeinteractor
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
  - Aaron Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-30 00:00:00.000000000 Z
11
+ date: 2019-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -247,10 +247,10 @@ licenses:
247
247
  - MIT
248
248
  metadata:
249
249
  bug_tracker_uri: https://github.com/aaronmallen/activeinteractor/issues
250
- changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v0.1.5/CHANGELOG.md
251
- documentation_uri: https://www.rubydoc.info/gems/activeinteractor/0.1.5
250
+ changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v0.1.6/CHANGELOG.md
251
+ documentation_uri: https://www.rubydoc.info/gems/activeinteractor/0.1.6
252
252
  hompage_uri: https://github.com/aaronmallen/activeinteractor
253
- source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v0.1.5
253
+ source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v0.1.6
254
254
  wiki_uri: https://github.com/aaronmallen/activeinteractor/wiki
255
255
  post_install_message:
256
256
  rdoc_options: []
@@ -267,7 +267,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  - !ruby/object:Gem::Version
268
268
  version: '0'
269
269
  requirements: []
270
- rubygems_version: 3.0.4
270
+ rubyforge_project:
271
+ rubygems_version: 2.7.7
271
272
  signing_key:
272
273
  specification_version: 4
273
274
  summary: Ruby interactors with ActiveModel::Validations