activeinteractor 0.1.4 → 0.1.5

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: 7f7136d8728ef016a9041ff462d8874af56028432ab839e8b7dab707b3ad1c59
4
- data.tar.gz: 04f08a4985a45385885b165f26fb65a93f9952ea4d2c0849312d5ff63075770a
3
+ metadata.gz: 8990e7455e8d135a08b562e71a81bc6ca0e14b4b98f25505d73c6b02e2638466
4
+ data.tar.gz: cf16acdae03eb8a3d15808fd4a01a112143878e502c20dd3a9d4dfc6396ebc09
5
5
  SHA512:
6
- metadata.gz: a6148b98fb26e34891e81fa84243f21d4db8460be907f69bae1a082ebce941ae3112c031aaba03086bba52b729fe358833b3a5fcbabb7e5fad505f29114eca6c
7
- data.tar.gz: daa7e71d54dfd86195e0487ef4f0da05df2cd3a47e4067e520a86876d87492dd04bcc406157214c55434404d82dfb5c4358adc24546e6f7e60998d6e2f562a9a
6
+ metadata.gz: ed677499ed9140e3dffedcee26f77f3b2967b51d24b7eabf594cacbfb1bf0f3a1bb9bd76f6a94a1a5d0ac61dd190380871391b76fc1afa29f65ae44fa57c1a75
7
+ data.tar.gz: 874df56e5d15a5bcdda48c4297c5b5b64feed016d9c0ea84ac450b907569d49f8298e1b1d49929cac7e949522c31f94ef7a5f64426b5ad4ffbc70e1a2ccddb14
data/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [v0.1.5] - 2019-06-30
11
+
12
+ ### Added
13
+
14
+ - [#39] `ActiveInteractor::Error` module
15
+
16
+ ### Deprecated
17
+
18
+ - [#39] `ActiveInteractor::Context::Failure` in favor of `ActiveInteractor::Error::ContextFailure`
19
+
20
+ ### Security
21
+
22
+ - [#33], [#37] Update rubocop: 0.67.2 → 0.72.0 (major)
23
+ - [#34] Various dependency updates
24
+ - [#38] Update yard: 0.9.19 → 0.9.20 (minor)
25
+
10
26
  ## [v0.1.4] - 2019-04-12
11
27
 
12
28
  ### Added
@@ -41,7 +57,8 @@ and this project adheres to [Semantic Versioning].
41
57
 
42
58
  <!-- versions -->
43
59
 
44
- [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.4..HEAD
60
+ [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.5..HEAD
61
+ [v0.1.5]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.4...v0.1.5
45
62
  [v0.1.4]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.3...v0.1.4
46
63
  [v0.1.3]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.2...v0.1.3
47
64
  [v0.1.2]: https://github.com/aaronmallen/activeinteractor/compare/v0.1.1...v0.1.2
@@ -54,3 +71,8 @@ and this project adheres to [Semantic Versioning].
54
71
  [#22]: https://github.com/aaronmallen/activeinteractor/pull/22
55
72
  [#25]: https://github.com/aaronmallen/activeinteractor/pull/25
56
73
  [#28]: https://github.com/aaronmallen/activeinteractor/pull/28
74
+ [#33]: https://github.com/aaronmallen/activeinteractor/pull/33
75
+ [#34]: https://github.com/aaronmallen/activeinteractor/pull/34
76
+ [#37]: https://github.com/aaronmallen/activeinteractor/pull/37
77
+ [#38]: https://github.com/aaronmallen/activeinteractor/pull/38
78
+ [#39]: https://github.com/aaronmallen/activeinteractor/pull/39
data/README.md CHANGED
@@ -124,7 +124,7 @@ context.success? # => false
124
124
 
125
125
  #### Dealing with Failure
126
126
 
127
- `context.fail!` always throws an exception of type `ActiveInteractor::Context::Failure`.
127
+ `context.fail!` always throws an exception of type `ActiveInteractor::Error::ContextFailure`.
128
128
 
129
129
  Normally, however, these exceptions are not seen. In the recommended usage, the consuming
130
130
  object invokes the interactor using the class method call, then checks the `success?` method of
@@ -180,7 +180,7 @@ context.occupation #=> nil
180
180
 
181
181
  #### Aliasing Attributes
182
182
 
183
- Some times you may want to use the same interactor functionality with different
183
+ Sometimes you may want to use the same interactor functionality with different
184
184
  model types having different naming conventions for similar attributes. We can
185
185
  inform the interactors context of these aliases with the `context_attribute_aliases`
186
186
  method on our interactors.
@@ -192,7 +192,7 @@ class MyInteractor < ActiveInteractor::Base
192
192
  end
193
193
 
194
194
  context = MyInteractor.perform(first_name: 'Aaron', sir_name: 'Allen')
195
- # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'
195
+ # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'>
196
196
  ```
197
197
 
198
198
  We can also pass an array of aliases to the attribute like this:
@@ -204,10 +204,10 @@ class MyInteractor < ActiveInteractor::Base
204
204
  end
205
205
 
206
206
  context = MyInteractor.perform(first_name: 'Aaron', sir_name: 'Allen')
207
- # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'
207
+ # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'>
208
208
 
209
209
  context = MyInteractor.perform(first_name: 'Aaron', sirname: 'Allen')
210
- # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'
210
+ # => <#MyInteractor::Context first_name='Aaron', last_name='Allen'>
211
211
  ```
212
212
 
213
213
  #### Validating the Context
@@ -4,11 +4,6 @@ require 'active_support/core_ext/array/wrap'
4
4
  require 'active_support/core_ext/class/attribute'
5
5
 
6
6
  module ActiveInteractor
7
- # ActiveInteractor::Context module
8
- #
9
- # @author Aaron Allen <hello@aaronmallen.me>
10
- # @since 0.0.1
11
- # @version 0.1
12
7
  module Context
13
8
  # Provides Context Attribute methods to included classes
14
9
  #
@@ -4,6 +4,8 @@ module ActiveInteractor
4
4
  module Context
5
5
  # Raised when an interactor context fails
6
6
  #
7
+ # @deprecated Use {#ActiveInteractor::Error::ContextFailure} instead
8
+ #
7
9
  # @author Aaron Allen <hello@aaronmallen.me>
8
10
  # @since 0.0.1
9
11
  # @version 0.2
@@ -49,15 +49,15 @@ module ActiveInteractor
49
49
  # #=> <#MyInteractor name='Aaron'>
50
50
  #
51
51
  # interactor.context.fail!
52
- # #=> ActiveInteractor::Context::Failure: <#MyInteractor::Context name='Aaron'>
52
+ # #=> ActiveInteractor::Error::ContextFailure: <#MyInteractor::Context name='Aaron'>
53
53
  #
54
54
  # @param errors [ActiveModel::Errors, Hash] errors to add to the context on failure
55
55
  # @see https://api.rubyonrails.org/classes/ActiveModel/Errors.html ActiveModel::Errors
56
- # @raise [Failure]
56
+ # @raise [Error::ContextFailure]
57
57
  def fail!(errors = {})
58
58
  self.errors.merge!(errors) unless errors.empty?
59
59
  @_failed = true
60
- raise Failure, self
60
+ raise Error::ContextFailure, self
61
61
  end
62
62
 
63
63
  # Whether the context instance has failed. By default, a new
@@ -73,7 +73,7 @@ module ActiveInteractor
73
73
  # false
74
74
  #
75
75
  # context.fail!
76
- # #=> ActiveInteractor::Context::Failure: <#MyInteractor::Context>
76
+ # #=> ActiveInteractor::Error::ContextFailure: <#MyInteractor::Context>
77
77
  #
78
78
  # context.failure?
79
79
  # #=> true
@@ -138,7 +138,7 @@ module ActiveInteractor
138
138
  # true
139
139
  #
140
140
  # context.fail!
141
- # #=> ActiveInteractor::Context::Failure: <#MyInteractor::Context>
141
+ # #=> ActiveInteractor::Error::ContextFailure: <#MyInteractor::Context>
142
142
  #
143
143
  # context.success?
144
144
  # #=> false
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveInteractor
4
+ # ActiveInteractor::Error module
5
+ #
6
+ # @author Aaron Allen <hello@aaronmallen.me>
7
+ # @since 0.1.5
8
+ # @version 0.1
9
+ module Error
10
+ # Raised when an interactor context fails
11
+ #
12
+ # @author Aaron Allen <hello@aaronmallen.me>
13
+ # @since 0.1.5
14
+ # @version 0.1
15
+ #
16
+ # @!attribute [r] context
17
+ # @return [Base] an instance of {Base}
18
+ class ContextFailure < StandardError
19
+ attr_reader :context
20
+
21
+ # A new instance of {ContextFailure}
22
+ # @param context [ActiveInteractor::Context::Base] an
23
+ # instance of {ActiveInteractor::Context::Base}
24
+ # @return [ContextFailure] a new instance of {ContextFailure}
25
+ def initialize(context = nil)
26
+ @context = context
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
@@ -18,17 +18,17 @@ module ActiveInteractor
18
18
  @interactor = clone_interactor(interactor)
19
19
  end
20
20
 
21
- # Calls {#execute_perform!} and rescues {ActiveInteractor::Context::Failure}
21
+ # Calls {#execute_perform!} and rescues {ActiveInteractor::Error::ContextFailure}
22
22
  # @return [ActiveInteractor::Context::Base] an instance of {ActiveInteractor::Context::Base}
23
23
  def execute_perform
24
24
  execute_perform!
25
- rescue ActiveInteractor::Context::Failure => exception
26
- ActiveInteractor.logger.error("ActiveInteractor: #{exception}")
25
+ rescue ActiveInteractor::Error::ContextFailure => e
26
+ ActiveInteractor.logger.error("ActiveInteractor: #{e}")
27
27
  context
28
28
  end
29
29
 
30
30
  # Calls {Interactor#perform} with callbacks and context validation
31
- # @raise [ActiveInteractor::Context::Failure] if the context fails
31
+ # @raise [ActiveInteractor::Error::ContextFailure] if the context fails
32
32
  # @return [ActiveInteractor::Context::Base] an instance of {ActiveInteractor::Context::Base}
33
33
  def execute_perform!
34
34
  run_callbacks :perform do
@@ -36,7 +36,7 @@ module ActiveInteractor
36
36
 
37
37
  # Invoke an Interactor. The {.perform!} method behaves identically to
38
38
  # the {.perform} method with one notable exception. If the context is failed
39
- # during invocation of the interactor, the {ActiveInteractor::Context::Failure}
39
+ # during invocation of the interactor, the {ActiveInteractor::Error::ContextFailure}
40
40
  # is raised.
41
41
  #
42
42
  # @example Run an interactor
@@ -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.4'
6
+ VERSION = '0.1.5'
7
7
  end
@@ -36,6 +36,10 @@ module ActiveInteractor
36
36
  autoload :Interactor
37
37
  autoload :Organizer
38
38
 
39
+ eager_autoload do
40
+ autoload :Error
41
+ end
42
+
39
43
  class << self
40
44
  # The ActiveInteractor configuration
41
45
  # @return [ActiveInteractor::Configuration] the configuration instance
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.4
4
+ version: 0.1.5
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-04-12 00:00:00.000000000 Z
11
+ date: 2019-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -56,14 +56,14 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.17'
59
+ version: '2.0'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '1.17'
66
+ version: '2.0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: github-markup
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '10.0'
101
+ version: '12.3'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '10.0'
108
+ version: '12.3'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: redcarpet
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -154,14 +154,14 @@ dependencies:
154
154
  requirements:
155
155
  - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: '0.66'
157
+ version: '0.67'
158
158
  type: :development
159
159
  prerelease: false
160
160
  version_requirements: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - "~>"
163
163
  - !ruby/object:Gem::Version
164
- version: '0.66'
164
+ version: '0.67'
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: simplecov
167
167
  requirement: !ruby/object:Gem::Requirement
@@ -222,6 +222,7 @@ files:
222
222
  - lib/active_interactor/context.rb
223
223
  - lib/active_interactor/context/attributes.rb
224
224
  - lib/active_interactor/context/errors.rb
225
+ - lib/active_interactor/error.rb
225
226
  - lib/active_interactor/interactor.rb
226
227
  - lib/active_interactor/interactor/callbacks.rb
227
228
  - lib/active_interactor/interactor/context.rb
@@ -246,10 +247,10 @@ licenses:
246
247
  - MIT
247
248
  metadata:
248
249
  bug_tracker_uri: https://github.com/aaronmallen/activeinteractor/issues
249
- changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v0.1.4/CHANGELOG.md
250
- documentation_uri: https://www.rubydoc.info/gems/activeinteractor/0.1.4
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
251
252
  hompage_uri: https://github.com/aaronmallen/activeinteractor
252
- source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v0.1.4
253
+ source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v0.1.5
253
254
  wiki_uri: https://github.com/aaronmallen/activeinteractor/wiki
254
255
  post_install_message:
255
256
  rdoc_options: []
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  - !ruby/object:Gem::Version
267
268
  version: '0'
268
269
  requirements: []
269
- rubygems_version: 3.0.3
270
+ rubygems_version: 3.0.4
270
271
  signing_key:
271
272
  specification_version: 4
272
273
  summary: Ruby interactors with ActiveModel::Validations