servactory 2.9.0.rc1 → 2.9.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca75399cdb14c4dc3b28703e9c3b2baf353f0612d8414de865f780a69dc56e74
4
- data.tar.gz: 74c08748d40a6233942c5c4b0b34f7b0ccb0a63776468d98ea08fda660b826fd
3
+ metadata.gz: 3a295d5b65040b9767438b436911e505ba6fa55adc08eff17b4519ca590821fb
4
+ data.tar.gz: b822546868d45ea6d96af38844992346d291328f7fc45479d07885b96cbe2bde
5
5
  SHA512:
6
- metadata.gz: f48fd065703fde42c80f14dae2045ea1af0c31d66c5eece2ccd4cb94358c089d7ca4e59417588a6f40dbd77376786377ad4ef90285f4d6a545925d5ecc0f0f8e
7
- data.tar.gz: c495107855b7a1939717457638e7171ef1deb9f979426dbdc5084c84ecc78b87bc38688a71df458a9afc5ee5befe7141c78122f7f071af00c5120ef15a0480a7
6
+ metadata.gz: b13d1f7b5e0ffc8d315a4b4c4749ac71f06d75a271d40158945d227f0dd5b9258bd28afbb7cf020a4432cf1976a8253f9a0983593a6358600a280064fc4a725c
7
+ data.tar.gz: f82304135dff9cc2030b6946f0b7b30b10fb919f24170215f76488eb534920cd818716b15464b180ec8e3a67f9dc8934056c6e3b18f94f92af646935a3f8265d
@@ -9,8 +9,8 @@ en:
9
9
  cannot_be_overwritten: "[%{service_class_name}] The following methods cannot be overwritten: %{list_of_methods}"
10
10
  inputs:
11
11
  undefined:
12
- getter: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
13
- setter: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
12
+ for_fetch: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
13
+ for_assign: "[%{service_class_name}] Undefined input attribute `%{input_name}`"
14
14
  validations:
15
15
  inclusion:
16
16
  default_error: "[%{service_class_name}] Wrong value in `%{input_name}`, must be one of `%{input_inclusion}`"
@@ -49,8 +49,8 @@ en:
49
49
  error: "[%{service_class_name}] Conflict in `%{input_name}` input options: `%{conflict_code}`"
50
50
  internals:
51
51
  undefined:
52
- getter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
53
- setter: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
52
+ for_fetch: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
53
+ for_assign: "[%{service_class_name}] Undefined internal attribute `%{internal_name}`"
54
54
  validations:
55
55
  inclusion:
56
56
  default_error: "[%{service_class_name}] Wrong value in `%{internal_name}`, must be one of `%{internal_inclusion}`"
@@ -81,8 +81,8 @@ en:
81
81
  wrong_element_type: "[%{service_class_name}] Wrong type in internal attribute hash `%{internal_name}`, expected `%{expected_type}` for `%{key_name}`, got `%{given_type}`"
82
82
  outputs:
83
83
  undefined:
84
- getter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
85
- setter: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
84
+ for_fetch: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
85
+ for_assign: "[%{service_class_name}] Undefined output attribute `%{output_name}`"
86
86
  validations:
87
87
  inclusion:
88
88
  default_error: "[%{service_class_name}] Wrong value in `%{output_name}`, must be one of `%{output_inclusion}`"
@@ -9,8 +9,8 @@ ru:
9
9
  cannot_be_overwritten: "[%{service_class_name}] Нельзя перезаписать следующие методы: %{list_of_methods}"
10
10
  inputs:
11
11
  undefined:
12
- getter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
13
- setter: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
12
+ for_fetch: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
13
+ for_assign: "[%{service_class_name}] Неизвестный входящий атрибут `%{input_name}`"
14
14
  validations:
15
15
  inclusion:
16
16
  default_error: "[%{service_class_name}] Неправильное значение в `%{input_name}`, должно быть одним из `%{input_inclusion}`"
@@ -49,8 +49,8 @@ ru:
49
49
  error: "[%{service_class_name}] Конфликт в опциях инпута `%{input_name}`: `%{conflict_code}`"
50
50
  internals:
51
51
  undefined:
52
- getter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
53
- setter: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
52
+ for_fetch: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
53
+ for_assign: "[%{service_class_name}] Неизвестный внутренний атрибут `%{internal_name}`"
54
54
  validations:
55
55
  inclusion:
56
56
  default_error: "[%{service_class_name}] Неправильное значение в `%{internal_name}`, должно быть одним из `%{internal_inclusion}`"
@@ -81,8 +81,8 @@ ru:
81
81
  wrong_element_type: "[%{service_class_name}] Неправильный тип в хеше внутреннего атрибута `%{internal_name}`, для `%{key_name}` ожидалось `%{expected_type}`, получено `%{given_type}`"
82
82
  outputs:
83
83
  undefined:
84
- getter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
85
- setter: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
84
+ for_fetch: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
85
+ for_assign: "[%{service_class_name}] Неизвестный выходящий атрибут `%{output_name}`"
86
86
  validations:
87
87
  inclusion:
88
88
  default_error: "[%{service_class_name}] Неправильное значение в `%{output_name}`, должно быть одним из `%{output_inclusion}`"
@@ -29,9 +29,9 @@ module Servactory
29
29
  if name.to_s.end_with?("=")
30
30
  prepared_name = name.to_s.delete("=").to_sym
31
31
 
32
- raise_error_for(:setter, prepared_name)
32
+ raise_error_for(:assign, prepared_name)
33
33
  else
34
- getter_with(name:) { raise_error_for(:getter, name) }
34
+ fetch_with(name:) { raise_error_for(:fetch, name) }
35
35
  end
36
36
  end
37
37
 
@@ -42,7 +42,7 @@ module Servactory
42
42
  private
43
43
 
44
44
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
45
- def getter_with(name:, &block)
45
+ def fetch_with(name:, &block)
46
46
  input_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
47
47
 
48
48
  input = @collection_of_inputs.find_by(name: input_name)
@@ -100,11 +100,15 @@ module Servactory
100
100
 
101
101
  def raise_error_for(type, name)
102
102
  message_text = @context.send(:servactory_service_info).translate(
103
- "inputs.undefined.#{type}",
103
+ "inputs.undefined.for_#{type}",
104
104
  input_name: name
105
105
  )
106
106
 
107
- raise @context.class.config.input_exception_class.new(message: message_text, input_name: name)
107
+ raise @context.class.config.input_exception_class.new(
108
+ context: @context,
109
+ message: message_text,
110
+ input_name: name
111
+ )
108
112
  end
109
113
  end
110
114
  end
@@ -25,9 +25,9 @@ module Servactory
25
25
  if name.to_s.end_with?("=")
26
26
  prepared_name = name.to_s.delete("=").to_sym
27
27
 
28
- setter_with(prepared_name:, value: args.pop) { raise_error_for(:setter, prepared_name) }
28
+ assign_with(prepared_name:, value: args.pop) { raise_error_for(:assign, prepared_name) }
29
29
  else
30
- getter_with(name:) { raise_error_for(:getter, name) }
30
+ fetch_with(name:) { raise_error_for(:fetch, name) }
31
31
  end
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module Servactory
37
37
 
38
38
  private
39
39
 
40
- def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
40
+ def assign_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
41
41
  return yield unless @collection_of_internals.names.include?(prepared_name)
42
42
 
43
43
  internal = @collection_of_internals.find_by(name: prepared_name) # ::Servactory::Internals::Internal
@@ -53,7 +53,7 @@ module Servactory
53
53
  @context.send(:servactory_service_store).assign_internal(internal.name, value)
54
54
  end
55
55
 
56
- def getter_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
56
+ def fetch_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
57
57
  internal_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
58
58
  internal = @collection_of_internals.find_by(name: internal_name)
59
59
 
@@ -70,11 +70,14 @@ module Servactory
70
70
 
71
71
  def raise_error_for(type, name)
72
72
  message_text = @context.send(:servactory_service_info).translate(
73
- "internals.undefined.#{type}",
73
+ "internals.undefined.for_#{type}",
74
74
  internal_name: name
75
75
  )
76
76
 
77
- raise @context.class.config.internal_exception_class.new(message: message_text)
77
+ raise @context.class.config.internal_exception_class.new(
78
+ context: @context,
79
+ message: message_text
80
+ )
78
81
  end
79
82
  end
80
83
  end
@@ -25,9 +25,9 @@ module Servactory
25
25
  if name.to_s.end_with?("=")
26
26
  prepared_name = name.to_s.delete("=").to_sym
27
27
 
28
- setter_with(prepared_name:, value: args.pop) { raise_error_for(:setter, prepared_name) }
28
+ assign_with(prepared_name:, value: args.pop) { raise_error_for(:assign, prepared_name) }
29
29
  else
30
- getter_with(name:) { raise_error_for(:getter, name) }
30
+ fetch_with(name:) { raise_error_for(:fetch, name) }
31
31
  end
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module Servactory
37
37
 
38
38
  private
39
39
 
40
- def setter_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
40
+ def assign_with(prepared_name:, value:, &block) # rubocop:disable Lint/UnusedMethodArgument
41
41
  return yield unless @collection_of_outputs.names.include?(prepared_name)
42
42
 
43
43
  output = @collection_of_outputs.find_by(name: prepared_name)
@@ -53,7 +53,7 @@ module Servactory
53
53
  @context.send(:servactory_service_store).assign_output(output.name, value)
54
54
  end
55
55
 
56
- def getter_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
56
+ def fetch_with(name:, &block) # rubocop:disable Metrics/AbcSize, Lint/UnusedMethodArgument
57
57
  output_name = @context.class.config.predicate_methods_enabled? ? name.to_s.chomp("?").to_sym : name
58
58
  output = @collection_of_outputs.find_by(name: output_name)
59
59
 
@@ -70,11 +70,14 @@ module Servactory
70
70
 
71
71
  def raise_error_for(type, name)
72
72
  message_text = @context.send(:servactory_service_info).translate(
73
- "outputs.undefined.#{type}",
73
+ "outputs.undefined.for_#{type}",
74
74
  output_name: name
75
75
  )
76
76
 
77
- raise @context.class.config.output_exception_class.new(message: message_text)
77
+ raise @context.class.config.output_exception_class.new(
78
+ context: @context,
79
+ message: message_text
80
+ )
78
81
  end
79
82
  end
80
83
  end
@@ -48,6 +48,7 @@ module Servactory
48
48
 
49
49
  def fail_input!(input_name, message:, meta: nil)
50
50
  raise self.class.config.input_exception_class.new(
51
+ context: self,
51
52
  input_name:,
52
53
  message:,
53
54
  meta:
@@ -56,6 +57,7 @@ module Servactory
56
57
 
57
58
  def fail_internal!(internal_name, message:, meta: nil)
58
59
  raise self.class.config.internal_exception_class.new(
60
+ context: self,
59
61
  internal_name:,
60
62
  message:,
61
63
  meta:
@@ -64,6 +66,7 @@ module Servactory
64
66
 
65
67
  def fail_output!(output_name, message:, meta: nil)
66
68
  raise self.class.config.output_exception_class.new(
69
+ context: self,
67
70
  output_name:,
68
71
  message:,
69
72
  meta:
@@ -3,11 +3,13 @@
3
3
  module Servactory
4
4
  module Exceptions
5
5
  class Input < Base
6
- attr_reader :message,
6
+ attr_reader :service,
7
+ :message,
7
8
  :input_name,
8
9
  :meta
9
10
 
10
- def initialize(message:, input_name: nil, meta: nil)
11
+ def initialize(context:, message:, input_name: nil, meta: nil)
12
+ @service = context.send(:servactory_service_info)
11
13
  @message = message
12
14
  @input_name = input_name&.to_sym
13
15
  @meta = meta
@@ -3,11 +3,13 @@
3
3
  module Servactory
4
4
  module Exceptions
5
5
  class Internal < Base
6
- attr_reader :message,
6
+ attr_reader :service,
7
+ :message,
7
8
  :internal_name,
8
9
  :meta
9
10
 
10
- def initialize(message:, internal_name: nil, meta: nil)
11
+ def initialize(context:, message:, internal_name: nil, meta: nil)
12
+ @service = context.send(:servactory_service_info)
11
13
  @message = message
12
14
  @internal_name = internal_name&.to_sym
13
15
  @meta = meta
@@ -3,11 +3,13 @@
3
3
  module Servactory
4
4
  module Exceptions
5
5
  class Output < Base
6
- attr_reader :message,
6
+ attr_reader :service,
7
+ :message,
7
8
  :output_name,
8
9
  :meta
9
10
 
10
- def initialize(message:, output_name: nil, meta: nil)
11
+ def initialize(context:, message:, output_name: nil, meta: nil)
12
+ @service = context.send(:servactory_service_info)
11
13
  @message = message
12
14
  @output_name = output_name&.to_sym
13
15
  @meta = meta
@@ -35,6 +35,7 @@ module Servactory
35
35
  )
36
36
 
37
37
  raise @context.class.config.input_exception_class.new(
38
+ context: @context,
38
39
  message: message_text,
39
40
  input_name: input.name
40
41
  )
@@ -22,7 +22,10 @@ module Servactory
22
22
  unnecessary_attributes: unnecessary_attributes.join(", ")
23
23
  )
24
24
 
25
- raise @context.class.config.input_exception_class.new(message: message_text)
25
+ raise @context.class.config.input_exception_class.new(
26
+ context: @context,
27
+ message: message_text
28
+ )
26
29
  end
27
30
 
28
31
  private
@@ -73,7 +73,10 @@ module Servactory
73
73
  def raise_errors
74
74
  return if (tmp_errors = errors.not_blank).empty?
75
75
 
76
- raise @context.class.config.input_exception_class.new(message: tmp_errors.first)
76
+ raise @context.class.config.input_exception_class.new(
77
+ context: @context,
78
+ message: tmp_errors.first
79
+ )
77
80
  end
78
81
  end
79
82
  end
@@ -96,7 +96,7 @@ module Servactory
96
96
  name: :types,
97
97
  attribute: @attribute,
98
98
  validation_class: Servactory::Maintenance::Attributes::Validations::Type,
99
- original_value: Array(@options.fetch(:type)),
99
+ original_value: Array(@options.fetch(:type)).uniq,
100
100
  need_for_checks: true,
101
101
  body_fallback: nil,
102
102
  with_advanced_mode: false
@@ -72,7 +72,7 @@ module Servactory
72
72
 
73
73
  raise @context.class.config
74
74
  .public_send(:"#{@attribute.system_name}_exception_class")
75
- .new(message: tmp_errors.first)
75
+ .new(context: @context, message: tmp_errors.first)
76
76
  end
77
77
  end
78
78
  end
@@ -80,7 +80,7 @@ module Servactory
80
80
  value = object.fetch(schema_key, nil)
81
81
  prepared_value = prepare_value_from(schema_value:, value:, required: attribute_required)
82
82
 
83
- Array(attribute_type).any? { |type| prepared_value.is_a?(type) }
83
+ Array(attribute_type).uniq.any? { |type| prepared_value.is_a?(type) }
84
84
  end
85
85
 
86
86
  def should_be_checked_for?(object:, schema_key:, schema_value:, required:)
@@ -36,7 +36,7 @@ module Servactory
36
36
  end
37
37
 
38
38
  def validate_for!(attribute:, values:, option:)
39
- consists_of_types = Array(option.value)
39
+ consists_of_types = Array(option.value).uniq
40
40
 
41
41
  return [false, :required] if fails_presence_validation?(attribute:, values:, consists_of_types:)
42
42
 
@@ -110,7 +110,7 @@ module Servactory
110
110
 
111
111
  values = values&.flatten if values.respond_to?(:flatten)
112
112
 
113
- values.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
113
+ values.filter { |value| Array(option_value).uniq.exclude?(value.class) }.map(&:class).uniq.join(", ")
114
114
  end
115
115
  end
116
116
  end
@@ -5,7 +5,7 @@ module Servactory
5
5
  MAJOR = 2
6
6
  MINOR = 9
7
7
  PATCH = 0
8
- PRE = "rc1"
8
+ PRE = "rc2"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  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: 2.9.0.rc1
4
+ version: 2.9.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-17 00:00:00.000000000 Z
11
+ date: 2024-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport