servactory 1.4.5 → 1.4.7
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/README.md +7 -0
- data/config/locales/en.yml +33 -0
- data/lib/servactory/engine.rb +7 -0
- data/lib/servactory/input_arguments/checks/inclusion.rb +10 -3
- data/lib/servactory/input_arguments/checks/must.rb +26 -12
- data/lib/servactory/input_arguments/checks/required.rb +8 -5
- data/lib/servactory/input_arguments/checks/type.rb +14 -4
- data/lib/servactory/input_arguments/tools/find_unnecessary.rb +7 -2
- data/lib/servactory/input_arguments/tools/rules.rb +8 -3
- data/lib/servactory/internal_arguments/checks/type.rb +7 -2
- data/lib/servactory/output_arguments/checks/type.rb +7 -2
- data/lib/servactory/output_arguments/tools/conflicts.rb +7 -3
- data/lib/servactory/version.rb +1 -1
- data/lib/servactory.rb +2 -1
- metadata +28 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb2ed3b4e1672a4065624d3a71b210011fb793fc340319d62720502581bb9c15
|
4
|
+
data.tar.gz: 916e1cf10398a6d34baf87828acdacdbebdaf13a8e78736a3c60732e19149017
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75415f8a46cd15aa7a5a7943a2cef385a31ebc9f2b837f0149d5d95a0cae004fd232878e6b6fd5a0c8b539c439b2d6e3745a5e95deb349dae90566e3184943a
|
7
|
+
data.tar.gz: 59837e7e7339635926ce3c5bb4457b79dd9717d0bdc39ab91f9c9cb30cb30d32860a160ecf08d49504e2a3d2de136646734c5203a750bec8c3f814f3f3ba38ba
|
data/README.md
CHANGED
@@ -28,6 +28,7 @@ A set of tools for building reliable services of any complexity.
|
|
28
28
|
- [Internal attributes](#internal-attributes)
|
29
29
|
- [Stage](#stage)
|
30
30
|
- [Failures](#failures)
|
31
|
+
- [I18n](#i18n)
|
31
32
|
- [Testing](#testing)
|
32
33
|
- [Thanks](#thanks)
|
33
34
|
- [Contributing](#contributing)
|
@@ -389,6 +390,12 @@ def check!
|
|
389
390
|
end
|
390
391
|
```
|
391
392
|
|
393
|
+
## I18n
|
394
|
+
|
395
|
+
All texts are stored in the localization file. All texts can be changed or supplemented by new locales.
|
396
|
+
|
397
|
+
[See en.yml file](https://github.com/afuno/servactory/tree/main/config/locales/en.yml)
|
398
|
+
|
392
399
|
## Testing
|
393
400
|
|
394
401
|
Testing Servactory services is the same as testing regular Ruby classes.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
en:
|
2
|
+
servactory:
|
3
|
+
input_arguments:
|
4
|
+
checks:
|
5
|
+
inclusion:
|
6
|
+
default_error: "[%{service_class_name}] Wrong value in `%{input_name}`, must be one of `%{input_inclusion}`"
|
7
|
+
must:
|
8
|
+
default_error: "[%{service_class_name}] Input `%{input_name}` must \"%{code}\""
|
9
|
+
syntax_error: "[%{service_class_name}] Syntax error inside `%{code}` of `%{input_name}` input"
|
10
|
+
required:
|
11
|
+
default_error:
|
12
|
+
default: "[%{service_class_name}] Required input `%{input_name}` is missing"
|
13
|
+
for_array: "[%{service_class_name}] Required element in input array `%{input_name}` is missing"
|
14
|
+
type:
|
15
|
+
default_error:
|
16
|
+
default: "[%{service_class_name}] Wrong type of input `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
17
|
+
for_array: "[%{service_class_name}] Wrong type in input array `%{input_name}`, expected `%{expected_type}`"
|
18
|
+
tools:
|
19
|
+
find_unnecessary:
|
20
|
+
error: "[%{service_class_name}] Unexpected attributes: `%{unnecessary_attributes}`"
|
21
|
+
rules:
|
22
|
+
error: "[%{service_class_name}] Conflict in `%{input_name}` input options: `%{conflict_code}`"
|
23
|
+
internal_arguments:
|
24
|
+
checks:
|
25
|
+
type:
|
26
|
+
default_error: "[%{service_class_name}] Wrong type of internal argument `%{internal_argument_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
27
|
+
output_arguments:
|
28
|
+
checks:
|
29
|
+
type:
|
30
|
+
default_error: "[%{service_class_name}] Wrong type of output argument `%{output_argument_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
31
|
+
tools:
|
32
|
+
conflicts:
|
33
|
+
error: "[%{service_class_name}] Conflict between internal and output attributes `%{overlapping_attributes}`"
|
@@ -4,8 +4,14 @@ module Servactory
|
|
4
4
|
module InputArguments
|
5
5
|
module Checks
|
6
6
|
class Inclusion < Base
|
7
|
-
DEFAULT_MESSAGE = lambda do |service_class_name:, input:|
|
8
|
-
|
7
|
+
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:|
|
8
|
+
I18n.t(
|
9
|
+
"servactory.input_arguments.checks.inclusion.default_error",
|
10
|
+
service_class_name: service_class_name,
|
11
|
+
input_name: input.name,
|
12
|
+
input_inclusion: input.inclusion[:in],
|
13
|
+
value: value
|
14
|
+
)
|
9
15
|
end
|
10
16
|
|
11
17
|
private_constant :DEFAULT_MESSAGE
|
@@ -36,7 +42,8 @@ module Servactory
|
|
36
42
|
add_error(
|
37
43
|
DEFAULT_MESSAGE,
|
38
44
|
service_class_name: @context.class.name,
|
39
|
-
input: @input
|
45
|
+
input: @input,
|
46
|
+
value: @value
|
40
47
|
)
|
41
48
|
end
|
42
49
|
end
|
@@ -4,12 +4,28 @@ module Servactory
|
|
4
4
|
module InputArguments
|
5
5
|
module Checks
|
6
6
|
class Must < Base
|
7
|
-
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, code:|
|
8
|
-
|
9
|
-
"must
|
7
|
+
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:, code:|
|
8
|
+
I18n.t(
|
9
|
+
"servactory.input_arguments.checks.must.default_error",
|
10
|
+
service_class_name: service_class_name,
|
11
|
+
input_name: input.name,
|
12
|
+
value: value,
|
13
|
+
code: code
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
SYNTAX_ERROR_MESSAGE = lambda do |service_class_name:, input:, value:, code:, exception_message:|
|
18
|
+
I18n.t(
|
19
|
+
"servactory.input_arguments.checks.must.syntax_error",
|
20
|
+
service_class_name: service_class_name,
|
21
|
+
input_name: input.name,
|
22
|
+
value: value,
|
23
|
+
code: code,
|
24
|
+
exception_message: exception_message
|
25
|
+
)
|
10
26
|
end
|
11
27
|
|
12
|
-
private_constant :DEFAULT_MESSAGE
|
28
|
+
private_constant :DEFAULT_MESSAGE, :SYNTAX_ERROR_MESSAGE
|
13
29
|
|
14
30
|
def self.check(context:, input:, value:, check_key:, check_options:)
|
15
31
|
return unless should_be_checked_for?(input, check_key)
|
@@ -39,9 +55,10 @@ module Servactory
|
|
39
55
|
next if message.blank?
|
40
56
|
|
41
57
|
add_error(
|
42
|
-
|
58
|
+
message,
|
43
59
|
service_class_name: @context.class.name,
|
44
60
|
input: @input,
|
61
|
+
value: @value,
|
45
62
|
code: code
|
46
63
|
)
|
47
64
|
end
|
@@ -58,16 +75,13 @@ module Servactory
|
|
58
75
|
|
59
76
|
message.presence || DEFAULT_MESSAGE
|
60
77
|
rescue StandardError => e
|
61
|
-
message_text =
|
62
|
-
"[#{@context.class.name}] Syntax error inside `#{code}` of `#{@input.name}` input"
|
63
|
-
|
64
|
-
puts "#{message_text}: #{e}"
|
65
|
-
|
66
78
|
add_error(
|
67
|
-
|
79
|
+
SYNTAX_ERROR_MESSAGE,
|
68
80
|
service_class_name: @context.class.name,
|
69
81
|
input: @input,
|
70
|
-
|
82
|
+
value: @value,
|
83
|
+
code: code,
|
84
|
+
exception_message: e.message
|
71
85
|
)
|
72
86
|
end
|
73
87
|
end
|
@@ -5,11 +5,14 @@ module Servactory
|
|
5
5
|
module Checks
|
6
6
|
class Required < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, input:, value:|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
i18n_key = "servactory.input_arguments.checks.required.default_error."
|
9
|
+
i18n_key += input.array? && value.present? ? "for_array" : "default"
|
10
|
+
|
11
|
+
I18n.t(
|
12
|
+
i18n_key,
|
13
|
+
service_class_name: service_class_name,
|
14
|
+
input_name: input.name
|
15
|
+
)
|
13
16
|
end
|
14
17
|
|
15
18
|
private_constant :DEFAULT_MESSAGE
|
@@ -13,12 +13,22 @@ module Servactory
|
|
13
13
|
elsif array_message.is_a?(String) && array_message.present?
|
14
14
|
array_message
|
15
15
|
else
|
16
|
-
|
16
|
+
I18n.t(
|
17
|
+
"servactory.input_arguments.checks.type.default_error.for_array",
|
18
|
+
service_class_name: service_class_name,
|
19
|
+
input_name: input.name,
|
20
|
+
expected_type: expected_type,
|
21
|
+
given_type: given_type
|
22
|
+
)
|
17
23
|
end
|
18
24
|
else
|
19
|
-
|
20
|
-
"
|
21
|
-
|
25
|
+
I18n.t(
|
26
|
+
"servactory.input_arguments.checks.type.default_error.default",
|
27
|
+
service_class_name: service_class_name,
|
28
|
+
input_name: input.name,
|
29
|
+
expected_type: expected_type,
|
30
|
+
given_type: given_type
|
31
|
+
)
|
22
32
|
end
|
23
33
|
end
|
24
34
|
|
@@ -17,8 +17,13 @@ module Servactory
|
|
17
17
|
def check!
|
18
18
|
return if unnecessary_attributes.empty?
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
message_text = I18n.t(
|
21
|
+
"servactory.input_arguments.tools.find_unnecessary.error",
|
22
|
+
service_class_name: @context.class.name,
|
23
|
+
unnecessary_attributes: unnecessary_attributes.join(", ")
|
24
|
+
)
|
25
|
+
|
26
|
+
raise Servactory.configuration.input_argument_error_class, message_text
|
22
27
|
end
|
23
28
|
|
24
29
|
private
|
@@ -28,9 +28,14 @@ module Servactory
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def raise_error_for(input_argument)
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
message_text = I18n.t(
|
32
|
+
"servactory.input_arguments.tools.rules.error",
|
33
|
+
service_class_name: @context.class.name,
|
34
|
+
input_name: input_argument.name,
|
35
|
+
conflict_code: input_argument.conflict_code
|
36
|
+
)
|
37
|
+
|
38
|
+
raise Servactory.configuration.input_argument_error_class, message_text
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
@@ -5,8 +5,13 @@ module Servactory
|
|
5
5
|
module Checks
|
6
6
|
class Type < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, internal_argument:, expected_type:, given_type:|
|
8
|
-
|
9
|
-
"
|
8
|
+
I18n.t(
|
9
|
+
"servactory.internal_arguments.checks.type.default_error",
|
10
|
+
service_class_name: service_class_name,
|
11
|
+
internal_argument_name: internal_argument.name,
|
12
|
+
expected_type: expected_type,
|
13
|
+
given_type: given_type
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
private_constant :DEFAULT_MESSAGE
|
@@ -5,8 +5,13 @@ module Servactory
|
|
5
5
|
module Checks
|
6
6
|
class Type < Base
|
7
7
|
DEFAULT_MESSAGE = lambda do |service_class_name:, output_argument:, expected_type:, given_type:|
|
8
|
-
|
9
|
-
"
|
8
|
+
I18n.t(
|
9
|
+
"servactory.output_arguments.checks.type.default_error",
|
10
|
+
service_class_name: service_class_name,
|
11
|
+
output_argument_name: output_argument.name,
|
12
|
+
expected_type: expected_type,
|
13
|
+
given_type: given_type
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
private_constant :DEFAULT_MESSAGE
|
@@ -17,9 +17,13 @@ module Servactory
|
|
17
17
|
def check!
|
18
18
|
return if overlapping_attributes.empty?
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
message_text = I18n.t(
|
21
|
+
"servactory.output_arguments.tools.conflicts.error",
|
22
|
+
service_class_name: @context.class.name,
|
23
|
+
overlapping_attributes: overlapping_attributes.join(", ")
|
24
|
+
)
|
25
|
+
|
26
|
+
raise Servactory.configuration.output_argument_error_class, message_text
|
23
27
|
end
|
24
28
|
|
25
29
|
private
|
data/lib/servactory/version.rb
CHANGED
data/lib/servactory.rb
CHANGED
@@ -5,7 +5,6 @@ require "zeitwerk"
|
|
5
5
|
require "active_support/core_ext/string"
|
6
6
|
|
7
7
|
# require "servactory/support/loader"
|
8
|
-
# require "servactory/engine"
|
9
8
|
|
10
9
|
loader = Zeitwerk::Loader.for_gem
|
11
10
|
loader.inflector.inflect(
|
@@ -29,6 +28,8 @@ module Servactory
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
31
|
+
require "servactory/engine" if defined?(Rails::Engine)
|
32
|
+
|
32
33
|
# require_relative "servactory/exceptions"
|
33
34
|
|
34
35
|
# require_relative "servactory/base"
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
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.7
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '7.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.13'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: zeitwerk
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '2.6'
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rbs
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +173,7 @@ extra_rdoc_files: []
|
|
159
173
|
files:
|
160
174
|
- README.md
|
161
175
|
- Rakefile
|
176
|
+
- config/locales/en.yml
|
162
177
|
- lib/servactory.rb
|
163
178
|
- lib/servactory/base.rb
|
164
179
|
- lib/servactory/configuration/dsl.rb
|
@@ -171,6 +186,7 @@ files:
|
|
171
186
|
- lib/servactory/context/workspace.rb
|
172
187
|
- lib/servactory/context/workspace/error.rb
|
173
188
|
- lib/servactory/context/workspace/errors.rb
|
189
|
+
- lib/servactory/engine.rb
|
174
190
|
- lib/servactory/errors/base.rb
|
175
191
|
- lib/servactory/errors/failure.rb
|
176
192
|
- lib/servactory/errors/input_argument_error.rb
|