active_call 0.2.1 → 0.3.1
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 +4 -4
- data/.rubocop.yml +7 -0
- data/CHANGELOG.md +7 -1
- data/README.md +26 -7
- data/lib/active_call/base.rb +12 -4
- data/lib/active_call/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81d606b580bac8742336f42545faf106467556da7af433b8c241cf8d5fc82d8
|
4
|
+
data.tar.gz: 9d4b35592755f86e515eea53931aa81884748a625e8f925775e77dc8829532f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 305cc609ed620e2feb222b54e1eeaeff4327c20222debb96a9e25435f0568ed880e7c8821b0ce9c5844b5061fb83970633d8d4114eda28a6ffb5b5d4e6bae50c
|
7
|
+
data.tar.gz: 2cb69c2c5e36b64ab93d8fc7ecc415c341f9f6f3ac37801a8aa07827dce83e8f9458885f3fb7c2b06872da4fc6a8e05b391649e593d1d9abaa5b00632d23571d
|
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
data/README.md
CHANGED
@@ -30,20 +30,26 @@ Each service object must define only one public method named `call`.
|
|
30
30
|
|
31
31
|
1. **Before** invoking `call`.
|
32
32
|
|
33
|
-
- Validate the
|
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
|
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
|
|
49
|
+
- Return the service object.
|
50
|
+
|
51
|
+
If any validations fail during this flow, the service object gets returned without continuing with the subsequent steps.
|
52
|
+
|
47
53
|
### Example Service Object
|
48
54
|
|
49
55
|
Define a service object with optional validations and callbacks.
|
@@ -52,15 +58,19 @@ Define a service object with optional validations and callbacks.
|
|
52
58
|
require 'active_call'
|
53
59
|
|
54
60
|
class YourGem::SomeResource::CreateService < ActiveCall::Base
|
55
|
-
attr_reader :message
|
61
|
+
attr_reader :message, :another_service
|
56
62
|
|
57
63
|
validates :message, presence: true
|
58
64
|
|
65
|
+
validate on: :request do
|
66
|
+
errors.merge!(another_service.errors) unless another_service.success?
|
67
|
+
end
|
68
|
+
|
59
69
|
validate on: :response do
|
60
70
|
errors.add(:message, :invalid, message: 'cannot be baz') if response[:foo] == 'baz'
|
61
71
|
end
|
62
72
|
|
63
|
-
before_call :strip_message
|
73
|
+
before_call :call_another_service, :strip_message
|
64
74
|
|
65
75
|
after_call :log_response
|
66
76
|
|
@@ -74,6 +84,10 @@ class YourGem::SomeResource::CreateService < ActiveCall::Base
|
|
74
84
|
|
75
85
|
private
|
76
86
|
|
87
|
+
def call_another_service
|
88
|
+
@another_service = YourGem::SomeResource::GetService.call(id: '1')
|
89
|
+
end
|
90
|
+
|
77
91
|
def strip_message
|
78
92
|
@message.strip!
|
79
93
|
end
|
@@ -201,10 +215,15 @@ spec.add_dependency 'active_call'
|
|
201
215
|
|
202
216
|
Now start adding your service objects in the `lib` directory and make sure they inherit from `ActiveCall::Base`.
|
203
217
|
|
218
|
+
## Active Call Extensions
|
219
|
+
|
220
|
+
- [Active Call - API](https://rubygems.org/gems/active_call-api)
|
221
|
+
|
204
222
|
## Gems Using Active Call
|
205
223
|
|
206
|
-
- [nCino KYC DocFox](https://
|
207
|
-
- [Zoho Sign](https://
|
224
|
+
- [Active Call - nCino KYC DocFox](https://rubygems.org/gems/active_call-doc_fox)
|
225
|
+
- [Active Call - Zoho Sign](https://rubygems.org/gems/active_call-zoho_sign)
|
226
|
+
- [Active Call - Zoho CRM](https://rubygems.org/gems/active_call-zoho_crm)
|
208
227
|
|
209
228
|
## Development
|
210
229
|
|
@@ -214,7 +233,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
214
233
|
|
215
234
|
## Contributing
|
216
235
|
|
217
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
236
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/activecall/active_call.
|
218
237
|
|
219
238
|
## License
|
220
239
|
|
data/lib/active_call/base.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
|
data/lib/active_call/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2025-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -58,15 +58,15 @@ files:
|
|
58
58
|
- lib/active_call/error.rb
|
59
59
|
- lib/active_call/version.rb
|
60
60
|
- sig/active_call.rbs
|
61
|
-
homepage: https://github.com/
|
61
|
+
homepage: https://github.com/activecall/active_call
|
62
62
|
licenses:
|
63
63
|
- MIT
|
64
64
|
metadata:
|
65
65
|
allowed_push_host: https://rubygems.org
|
66
66
|
rubygems_mfa_required: 'true'
|
67
|
-
homepage_uri: https://github.com/
|
68
|
-
source_code_uri: https://github.com/
|
69
|
-
changelog_uri: https://github.com/
|
67
|
+
homepage_uri: https://github.com/activecall/active_call
|
68
|
+
source_code_uri: https://github.com/activecall/active_call
|
69
|
+
changelog_uri: https://github.com/activecall/active_call/blob/main/CHANGELOG.md
|
70
70
|
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|