interaktor 0.3.0 → 0.4.0

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: 750eeac422a483d0c47ed00a3e457e97c43a134e611962f3a2316335d5c1a942
4
- data.tar.gz: 6fb7f28d30d78c6dcca2ea25383bdb85576e83600d7de3cad58a13ffa5e14b94
3
+ metadata.gz: d187b41c956972596b434b05aa5e4b3f8558457953327e305c5d76165f7c195b
4
+ data.tar.gz: e123fbeb3e8c1db843cb41b54023ca71d077a6947f0a3a50e0ec5bd78dfd4ddb
5
5
  SHA512:
6
- metadata.gz: 239222c9b5d7633b6c011d9e14ff1ec65f9612a3e1f13709ce8326c35bef28455b84f749a063927bb97e5387b8fd561019b3ead8ce681c7efc23c523736c777c
7
- data.tar.gz: aaf8d1f62d5e86fbfa079ad2c3222d920eb3119999c7a4dc3809cb32799abe7bc8102db7bb431d3cf07f27cc06f9ef38abce9e22955396464440ccb61b9d6634
6
+ metadata.gz: 5549218310ebd0e3d0505eac4d43302f83c9508a0bee463f3a8c0f2042de5bfd25954aec67beae050a140606b14e75ce1e7ff8f0866726e5a24a09dd8071b4e6
7
+ data.tar.gz: a7eabf0b930c9efd51ec3407e119234d6a1d29aa3d88494bacde287cc0e3d67ae9882707d8636ddba7289c6889f536bcdbad22eebc47a8344b659828a0718f4b
@@ -1,6 +1,8 @@
1
1
  name: Publish
2
2
 
3
3
  on:
4
+ # Manually publish
5
+ workflow_dispatch:
4
6
  push:
5
7
  tags:
6
8
  - v*
@@ -11,11 +13,11 @@ jobs:
11
13
  runs-on: ubuntu-latest
12
14
 
13
15
  steps:
14
- - uses: actions/checkout@v2
16
+ - uses: actions/checkout@v3
15
17
  - name: Set up Ruby
16
- uses: actions/setup-ruby@v1
18
+ uses: ruby/setup-ruby@v1
17
19
  with:
18
- ruby-version: 2.5.x
20
+ ruby-version: 3.2
19
21
 
20
22
  - name: Publish to RubyGems
21
23
  run: |
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.8
1
+ 3.1.3
data/interaktor.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "interaktor"
3
- spec.version = "0.3.0"
3
+ spec.version = "0.4.0"
4
4
 
5
5
  spec.author = "Taylor Thurlow"
6
6
  spec.email = "thurlow@hey.com"
@@ -126,6 +126,11 @@ module Interaktor::Hooks
126
126
  hooks.each { |hook| after_hooks.unshift(hook) }
127
127
  end
128
128
 
129
+ def ensure_hook(*hooks, &block)
130
+ hooks << block if block
131
+ hooks.each { |hook| ensure_hooks.push(hook) }
132
+ end
133
+
129
134
  # Internal: An Array of declared hooks to run around Interaktor
130
135
  # invocation. The hooks appear in the order in which they will be run.
131
136
  #
@@ -182,6 +187,10 @@ module Interaktor::Hooks
182
187
  def after_hooks
183
188
  @after_hooks ||= []
184
189
  end
190
+
191
+ def ensure_hooks
192
+ @ensure_hooks ||= []
193
+ end
185
194
  end
186
195
 
187
196
  private
@@ -212,6 +221,8 @@ module Interaktor::Hooks
212
221
  yield
213
222
  run_after_hooks
214
223
  end
224
+ ensure
225
+ run_ensure_hooks
215
226
  end
216
227
 
217
228
  # Internal: Run around hooks.
@@ -237,6 +248,11 @@ module Interaktor::Hooks
237
248
  run_hooks(self.class.after_hooks)
238
249
  end
239
250
 
251
+
252
+ def run_ensure_hooks
253
+ run_hooks(self.class.ensure_hooks)
254
+ end
255
+
240
256
  # Internal: Run a colection of hooks. The "run_hooks" method is the common
241
257
  # interface by which collections of either before or after hooks are run.
242
258
  #
@@ -308,7 +308,95 @@ module Interaktor
308
308
  end
309
309
  end
310
310
 
311
- context "with around, before and after hooks" do
311
+ context "with an ensure_hook method" do
312
+ let(:hooked) {
313
+ build_hooked do
314
+ ensure_hook :add_ensure
315
+
316
+ private
317
+
318
+ def add_ensure
319
+ steps << :ensure
320
+ end
321
+ end
322
+ }
323
+
324
+ it "runs the after hook method" do
325
+ expect(hooked.process).to eq([
326
+ :process,
327
+ :ensure,
328
+ ])
329
+ end
330
+ end
331
+
332
+ context "with an ensure_hook block" do
333
+ let(:hooked) {
334
+ build_hooked do
335
+ ensure_hook do
336
+ steps << :ensure
337
+ end
338
+ end
339
+ }
340
+
341
+ it "runs the after hook block" do
342
+ expect(hooked.process).to eq([
343
+ :process,
344
+ :ensure,
345
+ ])
346
+ end
347
+ end
348
+
349
+ context "with an ensure_hook method and block in one call" do
350
+ let(:hooked) {
351
+ build_hooked do
352
+ ensure_hook :add_ensure1 do
353
+ steps << :ensure2
354
+ end
355
+
356
+ private
357
+
358
+ def add_ensure1
359
+ steps << :ensure1
360
+ end
361
+ end
362
+ }
363
+
364
+ it "runs the ensure_hook method and block in order" do
365
+ expect(hooked.process).to eq([
366
+ :process,
367
+ :ensure1,
368
+ :ensure2,
369
+ ])
370
+ end
371
+ end
372
+
373
+ context "with an ensure_hook method and block in multiple calls" do
374
+ let(:hooked) {
375
+ build_hooked do
376
+ ensure_hook do
377
+ steps << :ensure1
378
+ end
379
+
380
+ ensure_hook :add_ensure2
381
+
382
+ private
383
+
384
+ def add_ensure2
385
+ steps << :ensure2
386
+ end
387
+ end
388
+ }
389
+
390
+ it "runs the ensure_hook block and method in order" do
391
+ expect(hooked.process).to eq([
392
+ :process,
393
+ :ensure1,
394
+ :ensure2,
395
+ ])
396
+ end
397
+ end
398
+
399
+ context "with around, before, after and ensure_hook hooks" do
312
400
  let(:hooked) {
313
401
  build_hooked do
314
402
  around do |hooked|
@@ -338,6 +426,14 @@ module Interaktor
338
426
  after do
339
427
  steps << :after2
340
428
  end
429
+
430
+ ensure_hook do
431
+ steps << :ensure1
432
+ end
433
+
434
+ ensure_hook do
435
+ steps << :ensure2
436
+ end
341
437
  end
342
438
  }
343
439
 
@@ -352,6 +448,8 @@ module Interaktor
352
448
  :after1,
353
449
  :around_after2,
354
450
  :around_after1,
451
+ :ensure1,
452
+ :ensure2,
355
453
  ])
356
454
  end
357
455
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interaktor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Thurlow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2023-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-schema
@@ -76,13 +76,9 @@ files:
76
76
  - lib/interaktor/error/attribute_error.rb
77
77
  - lib/interaktor/error/attribute_schema_validation_error.rb
78
78
  - lib/interaktor/error/base.rb
79
- - lib/interaktor/error/disallowed_attribute_assignment_error.rb
80
79
  - lib/interaktor/error/missing_explicit_success_error.rb
81
- - lib/interaktor/error/option_error.rb
82
80
  - lib/interaktor/error/organizer_missing_passed_attribute_error.rb
83
81
  - lib/interaktor/error/organizer_success_attribute_missing_error.rb
84
- - lib/interaktor/error/unknown_attribute_error.rb
85
- - lib/interaktor/error/unknown_option_error.rb
86
82
  - lib/interaktor/failure.rb
87
83
  - lib/interaktor/hooks.rb
88
84
  - lib/interaktor/organizer.rb
@@ -113,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
109
  - !ruby/object:Gem::Version
114
110
  version: '0'
115
111
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.6.3
112
+ rubygems_version: 3.4.6
118
113
  signing_key:
119
114
  specification_version: 4
120
115
  summary: Simple service object implementation
@@ -1,9 +0,0 @@
1
- class Interaktor::Error::DisallowedAttributeAssignmentError < Interaktor::Error::AttributeError
2
- def message
3
- <<~MESSAGE.strip.tr("\n", "")
4
- Attempted a disallowed assignment to the '#{attributes.first}'
5
- attribute which was not included when the #{interaktor} interaktor was
6
- originally called.
7
- MESSAGE
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- class Interaktor::Error::OptionError < Interaktor::Error::Base
2
- # @return [Hash{Symbol=>Object}]
3
- attr_reader :options
4
-
5
- # @param interaktor [Class]
6
- # @param options [Hash{Symbol=>Object}]
7
- def initialize(interaktor, options)
8
- super(interaktor)
9
-
10
- @options = options
11
- end
12
-
13
- # @return [String]
14
- # @abstract
15
- def message
16
- raise NoMethodError
17
- end
18
- end
@@ -1,5 +0,0 @@
1
- class Interaktor::Error::UnknownAttributeError < Interaktor::Error::AttributeError
2
- def message
3
- "Unknown attribute(s) in call to #{interaktor}: #{attributes.join(", ")}"
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class Interaktor::Error::UnknownOptionError < Interaktor::Error::OptionError
2
- def message
3
- "Unknown option(s) in #{interaktor} interaktor: #{options.keys.join(", ")}"
4
- end
5
- end