servactory 1.4.5 → 1.4.7

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: 8878b890cc7b43a45e8ea3e982a27e5873ec4d1aeff1ac91f6ce9ea77cc98e38
4
- data.tar.gz: 4f2947b852d2f0e53965b79b88ce013ae442575dee4f6539b1a2684e242211a5
3
+ metadata.gz: eb2ed3b4e1672a4065624d3a71b210011fb793fc340319d62720502581bb9c15
4
+ data.tar.gz: 916e1cf10398a6d34baf87828acdacdbebdaf13a8e78736a3c60732e19149017
5
5
  SHA512:
6
- metadata.gz: 437c627bef5b24d7f5a5e7b3f4c3b75e207af58d37900d6a8c6cf8b73c69e6704feb575f01233362f1ce2c40f7c640d2900d3d58e416ea12ed682c9f23fd058b
7
- data.tar.gz: fc9a5f1a97cf8db5483df7be46f805a6c8f5598b559237a89c2409ee761d61204b79da375d3d0228133b88f4e60fe124c22519c6a314d39bb33dbf585cd5422a
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}`"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ class Engine < Rails::Engine
5
+ isolate_namespace Servactory
6
+ end
7
+ end
@@ -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
- "[#{service_class_name}] Wrong value in `#{input.name}`, must be one of `#{input.inclusion[:in]}`"
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
- "[#{service_class_name}] Input `#{input.name}` " \
9
- "must \"#{code.to_s.humanize(capitalize: false, keep_id_suffix: true)}\""
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
- DEFAULT_MESSAGE,
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
- message_text,
79
+ SYNTAX_ERROR_MESSAGE,
68
80
  service_class_name: @context.class.name,
69
81
  input: @input,
70
- code: code
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
- if input.array? && value.present?
9
- "[#{service_class_name}] Required element in input array `#{input.name}` is missing"
10
- else
11
- "[#{service_class_name}] Required input `#{input.name}` is missing"
12
- end
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
- "[#{service_class_name}] Wrong type in input array `#{input.name}`, expected `#{expected_type}`"
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
- "[#{service_class_name}] Wrong type of input `#{input.name}`, " \
20
- "expected `#{expected_type}`, " \
21
- "got `#{given_type}`"
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
- raise Servactory.configuration.input_argument_error_class,
21
- "[#{@context.class.name}] Unexpected attributes: `#{unnecessary_attributes.join(', ')}`"
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
- raise Servactory.configuration.input_argument_error_class,
32
- "[#{@context.class.name}] Conflict in `#{input_argument.name}` input " \
33
- "options: `#{input_argument.conflict_code}`"
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
- "The \"#{internal_argument.name}\" internal argument on \"#{service_class_name}\" must be of type " \
9
- "\"#{expected_type}\" but was \"#{given_type}\""
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
- "The \"#{output_argument.name}\" output argument on \"#{service_class_name}\" must be of type " \
9
- "\"#{expected_type}\" but was \"#{given_type}\""
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
- raise Servactory.configuration.output_argument_error_class,
21
- "The \"#{@context.class.name}\" service contains internal attributes that " \
22
- "conflict with outputs: \"#{overlapping_attributes.join(', ')}\""
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
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 4
7
- PATCH = 5
7
+ PATCH = 7
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
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.5
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-15 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: zeitwerk
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
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: '2.6'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
28
+ name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '7.0'
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: '7.0'
40
+ version: '1.13'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
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: '13.0'
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