active_call 0.2.1 → 0.3.0

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: d67030b5b5cf7b405b842c1295c33912ebaa2b6ad1aeaefa0807e1a0f4fef105
4
- data.tar.gz: 6b19ccf7e464102efe1e70ab0501ea6bb3aa8a781880f1492cca1bfeee9de576
3
+ metadata.gz: 31e782b9a67b967ad37abe80818b43aa445517aa99a4830e2ec158c67404922e
4
+ data.tar.gz: 587d98f44af3c0a36198ffb76367bf30f0b8eb22b342d0d3d361c452452faf7a
5
5
  SHA512:
6
- metadata.gz: 5b0aea3b486558cd5d81ead4cbc1e75c1ae97f1edef31b3d9ed796b04cdb78e24e6aeda57227ade6c927f7a90599dfe16c06dc8065b98dcbb340db8a27f279e4
7
- data.tar.gz: 46f8fa215650ff0373ada16c79a7bd3f2f5a73ff8aaea30081a6e59ade1a869ac3aff735c132d87bc3774708ef13c2dc7829d802774b238f6acd74a061589063
6
+ metadata.gz: 4354d1137d8dfc1dae8570ccc6fb1324f2999d9b099c3f2a0e1da1fe4b93aa99b39692029d6169263736772e8eadce59376f0cd25d9812da38080f7309d06502
7
+ data.tar.gz: a2875e4fd4b26027584f4c830befb94ea9dc799fbc70aacbe791d44a39fa679ff56817a22c25fa5816bb715a1d6555f9717332026410a6e1af3c66f7ae1282da
data/.rubocop.yml CHANGED
@@ -18,10 +18,17 @@ AllCops:
18
18
  Layout/LineEndStringConcatenationIndentation:
19
19
  EnforcedStyle: indented
20
20
 
21
+ Layout/LineLength:
22
+ AllowedPatterns:
23
+ - '#'
24
+
21
25
  Lint/MissingSuper:
22
26
  AllowedParentClasses:
23
27
  - ActiveCall::Base
24
28
 
29
+ Metrics/AbcSize:
30
+ Enabled: false
31
+
25
32
  Metrics/BlockLength:
26
33
  Exclude:
27
34
  - spec/*/**.rb
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2025-03-31
2
+
3
+ - Added `validate on: :request` which runs after `before_call` and before invoking `call`'.
2
4
 
3
5
  ## [0.2.1] - 2025-03-25
4
6
 
data/README.md CHANGED
@@ -30,17 +30,19 @@ Each service object must define only one public method named `call`.
30
30
 
31
31
  1. **Before** invoking `call`.
32
32
 
33
- - Validate the request with `validates`.
33
+ - Validate the service with `validates`.
34
34
 
35
35
  - Use the `before_call` hook to set up anything **after validation** passes.
36
36
 
37
+ - Validate the request with `validate on: :request`.
38
+
37
39
  2. **During** `call` invocation.
38
40
 
39
41
  - A `response` attribute gets set with the result of the `call` method.
40
42
 
41
43
  3. **After** invoking `call`.
42
44
 
43
- - Validate the response with `validate, on: :response`.
45
+ - Validate the response with `validate on: :response`.
44
46
 
45
47
  - Use the `after_call` hook to set up anything **after response validation** passes.
46
48
 
@@ -52,15 +54,19 @@ Define a service object with optional validations and callbacks.
52
54
  require 'active_call'
53
55
 
54
56
  class YourGem::SomeResource::CreateService < ActiveCall::Base
55
- attr_reader :message
57
+ attr_reader :message, :another_service
56
58
 
57
59
  validates :message, presence: true
58
60
 
61
+ validate on: :request do
62
+ errors.merge!(another_service.errors) unless another_service.success?
63
+ end
64
+
59
65
  validate on: :response do
60
66
  errors.add(:message, :invalid, message: 'cannot be baz') if response[:foo] == 'baz'
61
67
  end
62
68
 
63
- before_call :strip_message
69
+ before_call :call_another_service, :strip_message
64
70
 
65
71
  after_call :log_response
66
72
 
@@ -74,6 +80,10 @@ class YourGem::SomeResource::CreateService < ActiveCall::Base
74
80
 
75
81
  private
76
82
 
83
+ def call_another_service
84
+ @another_service = YourGem::SomeResource::GetService.call(id: '1')
85
+ end
86
+
77
87
  def strip_message
78
88
  @message.strip!
79
89
  end
@@ -201,10 +211,14 @@ spec.add_dependency 'active_call'
201
211
 
202
212
  Now start adding your service objects in the `lib` directory and make sure they inherit from `ActiveCall::Base`.
203
213
 
214
+ ## Active Call Extensions
215
+
216
+ - [Active Call - API](https://rubygems.org/gems/active_call-api)
217
+
204
218
  ## Gems Using Active Call
205
219
 
206
- - [nCino KYC DocFox](https://github.com/kobusjoubert/doc_fox)
207
- - [Zoho Sign](https://github.com/kobusjoubert/zoho_sign)
220
+ - [Active Call - nCino KYC DocFox](https://rubygems.org/gems/active_call-doc_fox)
221
+ - [Active Call - Zoho Sign](https://rubygems.org/gems/active_call-zoho_sign)
208
222
 
209
223
  ## Development
210
224
 
@@ -32,7 +32,7 @@ class ActiveCall::Base
32
32
  @abstract_class == true
33
33
  end
34
34
 
35
- # TODO: Refactor `call` and `call!`. The only differences are the two lines raising exceptions.
35
+ # TODO: Refactor `call` and `call!`. The only differences are the lines raising exceptions.
36
36
 
37
37
  # Using `call`
38
38
  #
@@ -63,14 +63,16 @@ class ActiveCall::Base
63
63
  def call(...)
64
64
  service_object = new(...)
65
65
  service_object.instance_variable_set(:@bang, false)
66
- return service_object if service_object.invalid?(except_on: :response)
66
+ return service_object if service_object.invalid?(except_on: [:request, :response])
67
67
 
68
68
  service_object.run_callbacks(:call) do
69
69
  next if service_object.is_a?(Enumerable)
70
70
 
71
+ service_object.validate(:request)
72
+ return service_object unless service_object.success?
73
+
71
74
  service_object.instance_variable_set(:@response, service_object.call)
72
75
  service_object.validate(:response)
73
-
74
76
  return service_object unless service_object.success?
75
77
  end
76
78
 
@@ -110,11 +112,17 @@ class ActiveCall::Base
110
112
  def call!(...)
111
113
  service_object = new(...)
112
114
  service_object.instance_variable_set(:@bang, true)
113
- raise ActiveCall::ValidationError, service_object.errors if service_object.invalid?(except_on: :response)
115
+
116
+ if service_object.invalid?(except_on: [:request, :response])
117
+ raise ActiveCall::ValidationError, service_object.errors
118
+ end
114
119
 
115
120
  service_object.run_callbacks(:call) do
116
121
  next if service_object.is_a?(Enumerable)
117
122
 
123
+ service_object.validate(:request)
124
+ raise ActiveCall::RequestError.new(nil, service_object.errors) unless service_object.success?
125
+
118
126
  service_object.instance_variable_set(:@response, service_object.call)
119
127
  service_object.validate(:response)
120
128
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCall
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_call
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kobus Joubert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-25 00:00:00.000000000 Z
11
+ date: 2025-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel