servactory 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/lib/servactory/base.rb +2 -0
- data/lib/servactory/context/store.rb +1 -1
- data/lib/servactory/context/workspace/errors.rb +3 -3
- data/lib/servactory/context/workspace.rb +1 -1
- data/lib/servactory/input_arguments/checks/base.rb +7 -7
- data/lib/servactory/input_arguments/checks/errors.rb +17 -0
- data/lib/servactory/input_arguments/collection.rb +1 -1
- data/lib/servactory/input_arguments/input_argument.rb +13 -3
- data/lib/servactory/input_arguments/options_collection.rb +1 -1
- data/lib/servactory/input_arguments/tools/check.rb +6 -4
- data/lib/servactory/input_arguments/tools/check_errors.rb +21 -0
- data/lib/servactory/input_arguments/tools/prepare.rb +1 -1
- data/lib/servactory/internal_arguments/collection.rb +1 -1
- data/lib/servactory/output_arguments/collection.rb +1 -1
- data/lib/servactory/stage/methods.rb +1 -1
- data/lib/servactory/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54a713971d52bebd38a97f473eb942be19f5c4029604aa26f0729cb1dc40f24a
|
4
|
+
data.tar.gz: 1b368e874cdf3c502328fe3dbf71758a3c0821140c1b0e9a595f6622b41ec1bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e412f4e06a1a21aa70a43a0f898f6d5fc0adcca1eaf7922edb80aa719313b9c2325d83ef41e34eda9c8cacc988e60b076938e23b1ff1e709d50aee9ce0f0b1
|
7
|
+
data.tar.gz: d871cef64e8249b89572f6b97e9fdd9410632d20a393ea77d59f36481acc7f0207bfa26e6c79749a2031962927b965955986f257ce298d554d8289f2f85bfaf4
|
data/README.md
CHANGED
@@ -26,6 +26,9 @@ A set of tools for building reliable services of any complexity.
|
|
26
26
|
- [Stage](#stage)
|
27
27
|
- [Failures](#failures)
|
28
28
|
- [Result](#result)
|
29
|
+
- [Testing](#testing)
|
30
|
+
- [Thanks](#thanks)
|
31
|
+
- [Contributing](#contributing)
|
29
32
|
|
30
33
|
## Requirements
|
31
34
|
|
@@ -160,6 +163,26 @@ class UsersService::Create < ApplicationService::Base
|
|
160
163
|
end
|
161
164
|
```
|
162
165
|
|
166
|
+
#### As
|
167
|
+
|
168
|
+
This option changes the name of the input within the service.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
class NotificationService::Create < ApplicationService::Base
|
172
|
+
input :customer, as: :user, type: User
|
173
|
+
|
174
|
+
output :notification, type: Notification
|
175
|
+
|
176
|
+
stage { make :create_notification! }
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def create_notification!
|
181
|
+
self.notification = Notification.create!(user: inputs.user)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
163
186
|
#### An array of specific values
|
164
187
|
|
165
188
|
```ruby
|
@@ -342,3 +365,19 @@ And then you can work with this result, for example, in this way:
|
|
342
365
|
```ruby
|
343
366
|
Notification::SendJob.perform_later(service_result.notification.id)
|
344
367
|
```
|
368
|
+
|
369
|
+
## Testing
|
370
|
+
|
371
|
+
Testing Servactory services is the same as testing regular Ruby classes.
|
372
|
+
|
373
|
+
## Thanks
|
374
|
+
|
375
|
+
Thanks to [@sunny](https://github.com/sunny) for [Service Actor](https://github.com/sunny/actor).
|
376
|
+
|
377
|
+
## Contributing
|
378
|
+
|
379
|
+
1. Fork it (https://github.com/afuno/servactory/fork);
|
380
|
+
2. Create your feature branch (`git checkout -b my-new-feature`);
|
381
|
+
3. Commit your changes (`git commit -am "Add some feature"`);
|
382
|
+
4. Push to the branch (`git push origin my-new-feature`);
|
383
|
+
5. Create a new Pull Request.
|
data/lib/servactory/base.rb
CHANGED
@@ -8,12 +8,12 @@ module Servactory
|
|
8
8
|
extend Forwardable
|
9
9
|
def_delegators :@collection, :<<, :filter, :reject, :empty?, :first
|
10
10
|
|
11
|
-
def initialize(collection =
|
11
|
+
def initialize(collection = Set.new)
|
12
12
|
@collection = collection
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
Errors.new(reject(&:blank?)
|
15
|
+
def not_blank
|
16
|
+
Errors.new(reject(&:blank?))
|
17
17
|
end
|
18
18
|
|
19
19
|
def for_fails
|
@@ -23,7 +23,7 @@ module Servactory
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def raise_first_fail
|
26
|
-
return if (tmp_errors = errors.for_fails.
|
26
|
+
return if (tmp_errors = errors.for_fails.not_blank).empty?
|
27
27
|
|
28
28
|
raise Servactory.configuration.failure_class, tmp_errors.first.message
|
29
29
|
end
|
@@ -4,18 +4,18 @@ module Servactory
|
|
4
4
|
module InputArguments
|
5
5
|
module Checks
|
6
6
|
class Base
|
7
|
-
def initialize
|
8
|
-
@errors = []
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :errors
|
12
|
-
|
13
7
|
protected
|
14
8
|
|
15
9
|
def add_error(message, **arguments)
|
16
10
|
message = message.call(**arguments) if message.is_a?(Proc)
|
17
11
|
|
18
|
-
errors.
|
12
|
+
errors.add(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def errors
|
18
|
+
@errors ||= Errors.new
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module InputArguments
|
5
|
+
module Checks
|
6
|
+
class Errors
|
7
|
+
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@collection, :add, :to_a
|
10
|
+
|
11
|
+
def initialize(*)
|
12
|
+
@collection = Set.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,10 +6,19 @@ module Servactory
|
|
6
6
|
ARRAY_DEFAULT_VALUE = ->(is: false, message: nil) { { is: is, message: message } }
|
7
7
|
|
8
8
|
attr_reader :name,
|
9
|
+
:internal_name,
|
9
10
|
:collection_of_options
|
10
11
|
|
11
|
-
|
12
|
+
# rubocop:disable Style/KeywordParametersOrder
|
13
|
+
def initialize(
|
14
|
+
name,
|
15
|
+
as: nil,
|
16
|
+
collection_of_options:,
|
17
|
+
type:,
|
18
|
+
**options
|
19
|
+
)
|
12
20
|
@name = name
|
21
|
+
@internal_name = as.present? ? as : name
|
13
22
|
@collection_of_options = collection_of_options
|
14
23
|
|
15
24
|
add_basic_options_with(type: type, options: options)
|
@@ -20,6 +29,7 @@ module Servactory
|
|
20
29
|
instance_variable_set(:"@#{option.name}", option.value)
|
21
30
|
end
|
22
31
|
end
|
32
|
+
# rubocop:enable Style/KeywordParametersOrder
|
23
33
|
|
24
34
|
def add_basic_options_with(type:, options:)
|
25
35
|
# Check Class: Servactory::InputArguments::Checks::Required
|
@@ -72,8 +82,8 @@ module Servactory
|
|
72
82
|
collection_of_options << Option.new(
|
73
83
|
name: :types,
|
74
84
|
input: self,
|
75
|
-
original_value: Array(type),
|
76
85
|
check_class: Servactory::InputArguments::Checks::Type,
|
86
|
+
original_value: Array(type),
|
77
87
|
need_for_checks: true,
|
78
88
|
value_fallback: nil,
|
79
89
|
with_advanced_mode: false
|
@@ -167,6 +177,7 @@ module Servactory
|
|
167
177
|
collection_of_options << Option.new(
|
168
178
|
name: :internal,
|
169
179
|
input: self,
|
180
|
+
check_class: nil,
|
170
181
|
define_input_methods: lambda do
|
171
182
|
<<-RUBY
|
172
183
|
def internal?
|
@@ -175,7 +186,6 @@ module Servactory
|
|
175
186
|
RUBY
|
176
187
|
end,
|
177
188
|
need_for_checks: false,
|
178
|
-
check_class: nil,
|
179
189
|
value_key: :is,
|
180
190
|
value_fallback: false,
|
181
191
|
**options
|
@@ -13,8 +13,6 @@ module Servactory
|
|
13
13
|
@incoming_arguments = incoming_arguments
|
14
14
|
@collection_of_input_arguments = collection_of_input_arguments
|
15
15
|
@collection_of_input_options = collection_of_input_options
|
16
|
-
|
17
|
-
@errors = []
|
18
16
|
end
|
19
17
|
|
20
18
|
def check!
|
@@ -42,7 +40,7 @@ module Servactory
|
|
42
40
|
check_options: check_options
|
43
41
|
)
|
44
42
|
|
45
|
-
|
43
|
+
errors.merge(errors_from_checks.to_a)
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
@@ -64,8 +62,12 @@ module Servactory
|
|
64
62
|
|
65
63
|
########################################################################
|
66
64
|
|
65
|
+
def errors
|
66
|
+
@errors ||= CheckErrors.new
|
67
|
+
end
|
68
|
+
|
67
69
|
def raise_errors
|
68
|
-
return if (tmp_errors =
|
70
|
+
return if (tmp_errors = errors.not_blank).empty?
|
69
71
|
|
70
72
|
raise Servactory.configuration.input_argument_error_class, tmp_errors.first
|
71
73
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module InputArguments
|
5
|
+
module Tools
|
6
|
+
class CheckErrors
|
7
|
+
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@collection, :merge, :reject, :first, :empty?
|
10
|
+
|
11
|
+
def initialize(collection = Set.new)
|
12
|
+
@collection = collection
|
13
|
+
end
|
14
|
+
|
15
|
+
def not_blank
|
16
|
+
CheckErrors.new(reject(&:blank?))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -31,7 +31,7 @@ module Servactory
|
|
31
31
|
input_value = @incoming_arguments.fetch(input.name, nil)
|
32
32
|
input_value = input.default if input.optional? && input_value.blank?
|
33
33
|
|
34
|
-
@inputs_variables[input.
|
34
|
+
@inputs_variables[input.internal_name] = input_value
|
35
35
|
|
36
36
|
return unless input.internal?
|
37
37
|
|
data/lib/servactory/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servactory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/servactory/errors/internal_argument_error.rb
|
178
178
|
- lib/servactory/errors/output_argument_error.rb
|
179
179
|
- lib/servactory/input_arguments/checks/base.rb
|
180
|
+
- lib/servactory/input_arguments/checks/errors.rb
|
180
181
|
- lib/servactory/input_arguments/checks/inclusion.rb
|
181
182
|
- lib/servactory/input_arguments/checks/must.rb
|
182
183
|
- lib/servactory/input_arguments/checks/required.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- lib/servactory/input_arguments/option.rb
|
188
189
|
- lib/servactory/input_arguments/options_collection.rb
|
189
190
|
- lib/servactory/input_arguments/tools/check.rb
|
191
|
+
- lib/servactory/input_arguments/tools/check_errors.rb
|
190
192
|
- lib/servactory/input_arguments/tools/find_unnecessary.rb
|
191
193
|
- lib/servactory/input_arguments/tools/prepare.rb
|
192
194
|
- lib/servactory/input_arguments/tools/rules.rb
|