servactory 1.9.2 → 1.9.4

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: e1976d91976a495a0b930a03ad29e12240bddf6cba102c118c0ec12f871a023d
4
- data.tar.gz: 1b6ec8440f14820138c8fd380de3b4a13cf3eda761493a082cf2c56ed3e8c133
3
+ metadata.gz: 8c6d95c37b2eb4ab39f0a16db06fcd1e6cf6c48957ecd4877d85deb019b881e2
4
+ data.tar.gz: 3ab4992dc15627edeb9f5745d560775e161e4e285c8a08ff89078bcb2abe88c7
5
5
  SHA512:
6
- metadata.gz: 06d9b0f22847032a47c7ea4c12a495bf4e4b451e5041ef91ca3be13e05597a98fa4857ffbd3c2d00cdbe7b14c4c47733cbccf4573e3be154e3051fdb1cc08259
7
- data.tar.gz: 3a9244a611b5c01f3fd4aff99a1784b399cff79a0a9c3207afc59114cca26c4a780dd80b7b1849f9f27a313780187208e8784bd51cff74f9d131f613c52193aa
6
+ metadata.gz: d00d1f0d3cf1bde448a10a6c3fe81c1e1a22a09f9c73793626fa1e037c1c933a09bfed784365146837daa397664cf1fb80164e972e46121b5003b21e3ab25bfe
7
+ data.tar.gz: a0c6488d9815a7833f382e136f853ed405117d5459101195fb8801535beb3db7adf1860dd1a9b7c2a0eed6607e85b4f01bec6fa6804a0082110ca702c5d87a05
@@ -1,6 +1,9 @@
1
1
  en:
2
2
  servactory:
3
3
  inputs:
4
+ undefined:
5
+ getter: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
6
+ setter: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
4
7
  checks:
5
8
  inclusion:
6
9
  default_error: "[%{service_class_name}] Wrong value in `%{input_name}`, must be one of `%{input_inclusion}`"
@@ -21,10 +24,16 @@ en:
21
24
  rules:
22
25
  error: "[%{service_class_name}] Conflict in `%{input_name}` input options: `%{conflict_code}`"
23
26
  internals:
27
+ undefined:
28
+ getter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
29
+ setter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
24
30
  checks:
25
31
  type:
26
32
  default_error: "[%{service_class_name}] Wrong type of internal attribute `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
27
33
  outputs:
34
+ undefined:
35
+ getter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
36
+ setter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
28
37
  checks:
29
38
  type:
30
39
  default_error: "[%{service_class_name}] Wrong type of output attribute `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
@@ -1,6 +1,9 @@
1
1
  ru:
2
2
  servactory:
3
3
  inputs:
4
+ undefined:
5
+ getter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
6
+ setter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
4
7
  checks:
5
8
  inclusion:
6
9
  default_error: "[%{service_class_name}] Неверное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
@@ -21,10 +24,16 @@ ru:
21
24
  rules:
22
25
  error: "[%{service_class_name}] Конфликт в опциях инпута `%{input_name}`: `%{conflict_code}`"
23
26
  internals:
27
+ undefined:
28
+ getter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
29
+ setter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
24
30
  checks:
25
31
  type:
26
32
  default_error: "[%{service_class_name}] Неверный тип внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
27
33
  outputs:
34
+ undefined:
35
+ getter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
36
+ setter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
28
37
  checks:
29
38
  type:
30
39
  default_error: "[%{service_class_name}] Неверный тип выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
@@ -12,9 +12,11 @@ module Servactory
12
12
 
13
13
  def method_missing(name, *args, &block)
14
14
  if name.to_s.end_with?("=")
15
- super
15
+ prepared_name = name.to_s.delete("=").to_sym
16
+
17
+ raise_error_for(:setter, prepared_name)
16
18
  else
17
- getter_with(name: name) { super }
19
+ getter_with(name: name) { raise_error_for(:getter, name) }
18
20
  end
19
21
  end
20
22
 
@@ -42,6 +44,16 @@ module Servactory
42
44
  input_value
43
45
  end
44
46
  end
47
+
48
+ def raise_error_for(type, name)
49
+ message_text = I18n.t(
50
+ "servactory.inputs.undefined.#{type}",
51
+ service_class_name: @context.class.name,
52
+ input_name: name
53
+ )
54
+
55
+ raise @context.class.config.input_error_class.new(message: message_text, input_name: name)
56
+ end
45
57
  end
46
58
  end
47
59
  end
@@ -11,9 +11,11 @@ module Servactory
11
11
 
12
12
  def method_missing(name, *args, &block)
13
13
  if name.to_s.end_with?("=")
14
- setter_with(name: name, value: args.pop) { super }
14
+ prepared_name = name.to_s.delete("=").to_sym
15
+
16
+ setter_with(prepared_name: prepared_name, value: args.pop) { raise_error_for(:setter, prepared_name) }
15
17
  else
16
- getter_with(name: name) { super }
18
+ getter_with(name: name) { raise_error_for(:getter, name) }
17
19
  end
18
20
  end
19
21
 
@@ -23,9 +25,7 @@ module Servactory
23
25
 
24
26
  private
25
27
 
26
- def setter_with(name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
27
- prepared_name = name.to_s.delete("=").to_sym
28
-
28
+ def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
29
29
  return yield unless @collection_of_internals.names.include?(prepared_name)
30
30
 
31
31
  internal = @collection_of_internals.find_by(name: prepared_name) # ::Servactory::Internals::Internal
@@ -55,6 +55,16 @@ module Servactory
55
55
  internal_value
56
56
  end
57
57
  end
58
+
59
+ def raise_error_for(type, name)
60
+ message_text = I18n.t(
61
+ "servactory.internals.undefined.#{type}",
62
+ service_class_name: @context.class.name,
63
+ internal_name: name
64
+ )
65
+
66
+ raise @context.class.config.input_error_class.new(message: message_text)
67
+ end
58
68
  end
59
69
  end
60
70
  end
@@ -11,9 +11,11 @@ module Servactory
11
11
 
12
12
  def method_missing(name, *args, &block)
13
13
  if name.to_s.end_with?("=")
14
- setter_with(name: name, value: args.pop) { super }
14
+ prepared_name = name.to_s.delete("=").to_sym
15
+
16
+ setter_with(prepared_name: prepared_name, value: args.pop) { raise_error_for(:setter, prepared_name) }
15
17
  else
16
- getter_with(name: name) { super }
18
+ getter_with(name: name) { raise_error_for(:getter, name) }
17
19
  end
18
20
  end
19
21
 
@@ -23,9 +25,7 @@ module Servactory
23
25
 
24
26
  private
25
27
 
26
- def setter_with(name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
27
- prepared_name = name.to_s.delete("=").to_sym
28
-
28
+ def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
29
29
  return yield unless @collection_of_outputs.names.include?(prepared_name)
30
30
 
31
31
  output = @collection_of_outputs.find_by(name: prepared_name) # ::Servactory::Outputs::Output
@@ -55,6 +55,16 @@ module Servactory
55
55
  output_value
56
56
  end
57
57
  end
58
+
59
+ def raise_error_for(type, name)
60
+ message_text = I18n.t(
61
+ "servactory.outputs.undefined.#{type}",
62
+ service_class_name: @context.class.name,
63
+ output_name: name
64
+ )
65
+
66
+ raise @context.class.config.output_error_class.new(message: message_text)
67
+ end
58
68
  end
59
69
  end
60
70
  end
@@ -42,7 +42,7 @@ module Servactory
42
42
  end
43
43
 
44
44
  def call_wrapper_with_methods(wrapper, rollback, methods)
45
- wrapper.call(methods: -> { call_methods(methods) })
45
+ wrapper.call(methods: -> { call_methods(methods) }, context: @context)
46
46
  rescue StandardError => e
47
47
  @context.send(rollback, e) if rollback.present?
48
48
  end
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 9
7
- PATCH = 2
7
+ PATCH = 4
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
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.9.2
4
+ version: 1.9.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-07-24 00:00:00.000000000 Z
11
+ date: 2023-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport