servactory 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/locales/en.yml +1 -4
- data/config/locales/ru.yml +33 -0
- data/lib/servactory/configuration/dsl.rb +20 -1
- data/lib/servactory/configuration/factory.rb +11 -7
- data/lib/servactory/context/callable.rb +1 -1
- data/lib/servactory/context/workspace.rb +3 -3
- data/lib/servactory/dsl.rb +15 -0
- data/lib/servactory/inputs/dsl.rb +1 -0
- data/lib/servactory/inputs/input.rb +5 -2
- data/lib/servactory/inputs/tools/find_unnecessary.rb +1 -1
- data/lib/servactory/inputs/tools/rules.rb +1 -1
- data/lib/servactory/inputs/tools/validation.rb +7 -2
- data/lib/servactory/internals/validations/base.rb +1 -1
- data/lib/servactory/methods/dsl.rb +3 -9
- data/lib/servactory/outputs/validations/base.rb +1 -1
- data/lib/servactory/version.rb +1 -1
- data/lib/servactory.rb +1 -21
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4195548749c897719881d14227c7526a0be6097b38123e8556470089e867958a
|
4
|
+
data.tar.gz: c096b1aacf6217243b1d292afad6cff733dfc955a3d720741de60c5a7d2420cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff98fb471d49bb6ffda9d31d8daead860313cf12725db2251b22bf69d170bec272376bd71f1f2319ff373c962f6a06822f8e83a435140799d6698acb1454674
|
7
|
+
data.tar.gz: e333261e7b6a7c5fd8cfc339ac312845bcd89b373100db21d330f89119ea3994fa5c9d66066c8b9b5705e648567513cd1ddbda6907aab4389c6b05475f36ede2
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ class UserService::Authenticate < Servactory::Base
|
|
41
41
|
private
|
42
42
|
|
43
43
|
def call
|
44
|
-
if (user = User.
|
44
|
+
if (user = User.authenticate_by(email: inputs.email, password: inputs.password)).present?
|
45
45
|
outputs.user = user
|
46
46
|
else
|
47
47
|
fail!(message: "Authentication failed")
|
data/config/locales/en.yml
CHANGED
@@ -28,9 +28,6 @@ en:
|
|
28
28
|
checks:
|
29
29
|
type:
|
30
30
|
default_error: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
|
31
|
-
tools:
|
32
|
-
conflicts:
|
33
|
-
error: "[%{service_class_name}] Conflict between internal and output attributes `%{overlapping_attributes}`"
|
34
31
|
methods:
|
35
32
|
call:
|
36
|
-
not_used: Nothing to perform. Use `make` or create a `call` method
|
33
|
+
not_used: Nothing to perform. Use `make` or create a `call` method.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
ru:
|
2
|
+
servactory:
|
3
|
+
inputs:
|
4
|
+
checks:
|
5
|
+
inclusion:
|
6
|
+
default_error: "[%{service_class_name}] Неверное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
|
7
|
+
must:
|
8
|
+
default_error: "[%{service_class_name}] Инпут `%{input_name}` должен \"%{code}\""
|
9
|
+
syntax_error: "[%{service_class_name}] Синтаксическая ошибка внутри `%{code}` инпута `%{input_name}`"
|
10
|
+
required:
|
11
|
+
default_error:
|
12
|
+
default: "[%{service_class_name}] Обязательный инпут `%{input_name}` отсутствует"
|
13
|
+
for_array: "[%{service_class_name}] Обязательный элемент в инпуте-массиве `%{input_name}` отсутствует"
|
14
|
+
type:
|
15
|
+
default_error:
|
16
|
+
default: "[%{service_class_name}] Неверный тип инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
17
|
+
for_array: "[%{service_class_name}] Неверный тип инпута-массива `%{input_name}`, ожидалось `%{expected_type}`"
|
18
|
+
tools:
|
19
|
+
find_unnecessary:
|
20
|
+
error: "[%{service_class_name}] Неожиданные атрибуты: `%{unnecessary_attributes}`"
|
21
|
+
rules:
|
22
|
+
error: "[%{service_class_name}] Конфликт в опциях инпута `%{input_name}`: `%{conflict_code}`"
|
23
|
+
internals:
|
24
|
+
checks:
|
25
|
+
type:
|
26
|
+
default_error: "[%{service_class_name}] Неверный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
27
|
+
outputs:
|
28
|
+
checks:
|
29
|
+
type:
|
30
|
+
default_error: "[%{service_class_name}] Неверный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
|
31
|
+
methods:
|
32
|
+
call:
|
33
|
+
not_used: Нечего исполнять. Используйте `make` или создайте метод `call`.
|
@@ -8,10 +8,29 @@ module Servactory
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
+
def inherited(child) # rubocop:disable Metrics/AbcSize
|
12
|
+
super
|
13
|
+
|
14
|
+
child.config.input_error_class = config.input_error_class
|
15
|
+
child.config.internal_error_class = config.internal_error_class
|
16
|
+
child.config.output_error_class = config.output_error_class
|
17
|
+
|
18
|
+
child.config.failure_class = config.failure_class
|
19
|
+
|
20
|
+
child.config.input_option_helpers = config.input_option_helpers
|
21
|
+
|
22
|
+
child.config.aliases_for_make = config.aliases_for_make
|
23
|
+
child.config.shortcuts_for_make = config.shortcuts_for_make
|
24
|
+
end
|
25
|
+
|
26
|
+
def config
|
27
|
+
@config ||= Servactory::Configuration::Setup.new
|
28
|
+
end
|
29
|
+
|
11
30
|
private
|
12
31
|
|
13
32
|
def configuration(&block)
|
14
|
-
@configuration_factory ||= Factory.new
|
33
|
+
@configuration_factory ||= Factory.new(config)
|
15
34
|
|
16
35
|
@configuration_factory.instance_eval(&block)
|
17
36
|
end
|
@@ -3,32 +3,36 @@
|
|
3
3
|
module Servactory
|
4
4
|
module Configuration
|
5
5
|
class Factory
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
6
10
|
def input_error_class(input_error_class)
|
7
|
-
|
11
|
+
@config.input_error_class = input_error_class
|
8
12
|
end
|
9
13
|
|
10
14
|
def output_error_class(output_error_class)
|
11
|
-
|
15
|
+
@config.output_error_class = output_error_class
|
12
16
|
end
|
13
17
|
|
14
18
|
def internal_error_class(internal_error_class)
|
15
|
-
|
19
|
+
@config.internal_error_class = internal_error_class
|
16
20
|
end
|
17
21
|
|
18
22
|
def failure_class(failure_class)
|
19
|
-
|
23
|
+
@config.failure_class = failure_class
|
20
24
|
end
|
21
25
|
|
22
26
|
def input_option_helpers(input_option_helpers)
|
23
|
-
|
27
|
+
@config.input_option_helpers.merge(input_option_helpers)
|
24
28
|
end
|
25
29
|
|
26
30
|
def aliases_for_make(aliases_for_make)
|
27
|
-
|
31
|
+
@config.aliases_for_make.merge(aliases_for_make)
|
28
32
|
end
|
29
33
|
|
30
34
|
def shortcuts_for_make(shortcuts_for_make)
|
31
|
-
|
35
|
+
@config.shortcuts_for_make.merge(shortcuts_for_make)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -29,14 +29,14 @@ module Servactory
|
|
29
29
|
alias out outputs
|
30
30
|
|
31
31
|
def fail_input!(input_name, message:)
|
32
|
-
raise
|
32
|
+
raise self.class.config.input_error_class.new(
|
33
33
|
input_name: input_name,
|
34
34
|
message: message
|
35
35
|
)
|
36
36
|
end
|
37
37
|
|
38
38
|
def fail!(message:, meta: nil)
|
39
|
-
raise
|
39
|
+
raise self.class.config.failure_class.new(message: message, meta: meta)
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -76,7 +76,7 @@ module Servactory
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def call
|
79
|
-
raise
|
79
|
+
raise self.class.config.failure_class.new(
|
80
80
|
message: I18n.t(
|
81
81
|
"servactory.methods.call.not_used",
|
82
82
|
service_class_name: self.class.name
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module DSL
|
5
|
+
def self.included(base)
|
6
|
+
base.include(Configuration::DSL)
|
7
|
+
base.include(Info::DSL)
|
8
|
+
base.include(Context::DSL)
|
9
|
+
base.include(Inputs::DSL)
|
10
|
+
base.include(Internals::DSL)
|
11
|
+
base.include(Outputs::DSL)
|
12
|
+
base.include(Methods::DSL)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -8,7 +8,8 @@ module Servactory
|
|
8
8
|
private_constant :ARRAY_DEFAULT_VALUE
|
9
9
|
|
10
10
|
attr_reader :name,
|
11
|
-
:internal_name
|
11
|
+
:internal_name,
|
12
|
+
:config
|
12
13
|
|
13
14
|
# rubocop:disable Style/KeywordParametersOrder
|
14
15
|
def initialize(
|
@@ -16,10 +17,12 @@ module Servactory
|
|
16
17
|
*helpers,
|
17
18
|
as: nil,
|
18
19
|
type:,
|
20
|
+
config:,
|
19
21
|
**options
|
20
22
|
)
|
21
23
|
@name = name
|
22
24
|
@internal_name = as.present? ? as : name
|
25
|
+
@config = config
|
23
26
|
|
24
27
|
options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
|
25
28
|
|
@@ -43,7 +46,7 @@ module Servactory
|
|
43
46
|
prepared_options = {}
|
44
47
|
|
45
48
|
helpers.each do |helper|
|
46
|
-
found_helper =
|
49
|
+
found_helper = config.input_option_helpers.find_by(name: helper)
|
47
50
|
|
48
51
|
next if found_helper.blank?
|
49
52
|
|
@@ -23,7 +23,7 @@ module Servactory
|
|
23
23
|
unnecessary_attributes: unnecessary_attributes.join(", ")
|
24
24
|
)
|
25
25
|
|
26
|
-
raise
|
26
|
+
raise @context.class.config.input_error_class.new(message: message_text)
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
@@ -43,7 +43,12 @@ module Servactory
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def process_validation_classes(
|
46
|
+
def process_validation_classes(
|
47
|
+
validation_class,
|
48
|
+
input:,
|
49
|
+
check_key:,
|
50
|
+
check_options:
|
51
|
+
)
|
47
52
|
validation_class.check(
|
48
53
|
context: @context,
|
49
54
|
input: input,
|
@@ -68,7 +73,7 @@ module Servactory
|
|
68
73
|
def raise_errors
|
69
74
|
return if (tmp_errors = errors.not_blank).empty?
|
70
75
|
|
71
|
-
raise
|
76
|
+
raise @context.class.config.input_error_class.new(message: tmp_errors.first)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
@@ -9,7 +9,7 @@ module Servactory
|
|
9
9
|
def raise_error_with(message, **attributes)
|
10
10
|
message = message.call(**attributes) if message.is_a?(Proc)
|
11
11
|
|
12
|
-
raise
|
12
|
+
raise @context.class.config.internal_error_class.new(message: message)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -68,13 +68,9 @@ module Servactory
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def method_missing(name, *args, &block)
|
71
|
-
if
|
72
|
-
return method_missing_for_aliases_for_make(name, *args, &block)
|
73
|
-
end
|
71
|
+
return method_missing_for_aliases_for_make(name, *args, &block) if config.aliases_for_make.include?(name)
|
74
72
|
|
75
|
-
if
|
76
|
-
return method_missing_for_shortcuts_for_make(name, *args, &block)
|
77
|
-
end
|
73
|
+
return method_missing_for_shortcuts_for_make(name, *args, &block) if config.shortcuts_for_make.include?(name)
|
78
74
|
|
79
75
|
super
|
80
76
|
end
|
@@ -97,9 +93,7 @@ module Servactory
|
|
97
93
|
end
|
98
94
|
|
99
95
|
def respond_to_missing?(name, *)
|
100
|
-
|
101
|
-
Servactory.configuration.shortcuts_for_make.include?(name) ||
|
102
|
-
super
|
96
|
+
config.aliases_for_make.include?(name) || config.shortcuts_for_make.include?(name) || super
|
103
97
|
end
|
104
98
|
|
105
99
|
def next_position
|
@@ -9,7 +9,7 @@ module Servactory
|
|
9
9
|
def raise_error_with(message, **attributes)
|
10
10
|
message = message.call(**attributes) if message.is_a?(Proc)
|
11
11
|
|
12
|
-
raise
|
12
|
+
raise @context.class.config.output_error_class.new(message: message)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/servactory/version.rb
CHANGED
data/lib/servactory.rb
CHANGED
@@ -4,32 +4,12 @@ require "zeitwerk"
|
|
4
4
|
|
5
5
|
require "active_support/core_ext/string"
|
6
6
|
|
7
|
-
# require "servactory/support/loader"
|
8
|
-
|
9
7
|
loader = Zeitwerk::Loader.for_gem
|
10
8
|
loader.inflector.inflect(
|
11
9
|
"dsl" => "DSL"
|
12
10
|
)
|
13
11
|
loader.setup
|
14
12
|
|
15
|
-
module Servactory
|
16
|
-
module_function
|
17
|
-
|
18
|
-
def configuration
|
19
|
-
@configuration ||= Servactory::Configuration::Setup.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def reset
|
23
|
-
@configuration = Servactory::Configuration::Setup.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def configure
|
27
|
-
yield(configuration)
|
28
|
-
end
|
29
|
-
end
|
13
|
+
module Servactory; end
|
30
14
|
|
31
15
|
require "servactory/engine" if defined?(Rails::Engine)
|
32
|
-
|
33
|
-
# require_relative "servactory/exceptions"
|
34
|
-
|
35
|
-
# require_relative "servactory/base"
|
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.8.
|
4
|
+
version: 1.8.8
|
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-07-
|
11
|
+
date: 2023-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- README.md
|
189
189
|
- Rakefile
|
190
190
|
- config/locales/en.yml
|
191
|
+
- config/locales/ru.yml
|
191
192
|
- lib/servactory.rb
|
192
193
|
- lib/servactory/base.rb
|
193
194
|
- lib/servactory/configuration/dsl.rb
|
@@ -199,6 +200,7 @@ files:
|
|
199
200
|
- lib/servactory/context/workspace/inputs.rb
|
200
201
|
- lib/servactory/context/workspace/internals.rb
|
201
202
|
- lib/servactory/context/workspace/outputs.rb
|
203
|
+
- lib/servactory/dsl.rb
|
202
204
|
- lib/servactory/engine.rb
|
203
205
|
- lib/servactory/errors/base.rb
|
204
206
|
- lib/servactory/errors/failure.rb
|
@@ -276,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
278
|
- !ruby/object:Gem::Version
|
277
279
|
version: '0'
|
278
280
|
requirements: []
|
279
|
-
rubygems_version: 3.4.
|
281
|
+
rubygems_version: 3.4.17
|
280
282
|
signing_key:
|
281
283
|
specification_version: 4
|
282
284
|
summary: A set of tools for building reliable services of any complexity
|