servactory 2.8.0 → 2.9.0.rc2

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: 2fd2afd31c63b79469991b78c2c30728aa2d268eeaf9deac3ea0e72c06db6614
4
- data.tar.gz: e11af49a2bc836b3f265c4dc48957106550b905c05682cb837099ed53a62c24a
3
+ metadata.gz: 3a295d5b65040b9767438b436911e505ba6fa55adc08eff17b4519ca590821fb
4
+ data.tar.gz: b822546868d45ea6d96af38844992346d291328f7fc45479d07885b96cbe2bde
5
5
  SHA512:
6
- metadata.gz: 7d22e4e63465bcc22943d6eb90085081ba299ea571cea5393fabc22dae15d434e05b51f78f7fd26d27d93d3775419d89c24a47c492c2a8808565e5a8d6f0bfc4
7
- data.tar.gz: cb529f9e8c66ef9de222ae4a66b0884635f1dda2435020a67d024c61686f6ffa1434e80b773e71a66c84776e55e305240bbc4e26c5cd4cfc22b5483500b8bff7
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}`"
@@ -6,7 +6,7 @@ module Servactory
6
6
  def call!(arguments = {})
7
7
  context = send(:new)
8
8
 
9
- _call!(context, **arguments)
9
+ _call!(context, arguments)
10
10
 
11
11
  config.result_class.success_for(context:)
12
12
  rescue config.success_class => e
@@ -16,7 +16,7 @@ module Servactory
16
16
  def call(arguments = {})
17
17
  context = send(:new)
18
18
 
19
- _call!(context, **arguments)
19
+ _call!(context, arguments)
20
20
 
21
21
  config.result_class.success_for(context:)
22
22
  rescue config.success_class => e
@@ -27,10 +27,12 @@ module Servactory
27
27
 
28
28
  private
29
29
 
30
- def _call!(context, **arguments)
30
+ def _call!(context, incoming_arguments)
31
+ incoming_arguments = Servactory::Utils.adapt(incoming_arguments)
32
+
31
33
  context.send(
32
34
  :_call!,
33
- incoming_arguments: arguments.symbolize_keys,
35
+ incoming_arguments:,
34
36
  collection_of_inputs:,
35
37
  collection_of_internals:,
36
38
  collection_of_outputs:,
@@ -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:)
@@ -13,7 +13,7 @@ module Servactory
13
13
  @attribute_type = attribute_type
14
14
  @attribute_type_plural = attribute_type.to_s.pluralize.to_sym
15
15
  @attribute_name = attribute_name
16
- @attributes = attributes
16
+ @attributes = attributes.is_a?(FalseClass) ? attributes : Servactory::Utils.adapt(attributes)
17
17
 
18
18
  @attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
19
19
 
@@ -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
@@ -2,7 +2,15 @@
2
2
 
3
3
  module Servactory
4
4
  module Utils
5
- module_function
5
+ extend self
6
+
7
+ def adapt(data)
8
+ if defined?(Datory::Base) && data.is_a?(Datory::Base)
9
+ data = Servactory::Utils.send(:instance_variables_to_hash_from, data)
10
+ end
11
+
12
+ data.symbolize_keys
13
+ end
6
14
 
7
15
  def fetch_hash_with_desired_attribute(attribute)
8
16
  return { input: attribute.class::Actor.new(attribute) } if really_input?(attribute)
@@ -97,5 +105,24 @@ module Servactory
97
105
  class_or_name
98
106
  end
99
107
  end
108
+
109
+ private
110
+
111
+ def instance_variables_to_hash_from(data) # rubocop:disable Metrics/MethodLength
112
+ data.instance_variables.to_h do |key|
113
+ value = data.instance_variable_get(key)
114
+
115
+ value =
116
+ if value.is_a?(Set) || value.is_a?(Array)
117
+ value.map { |item| instance_variables_to_hash_from(item) }
118
+ elsif value.is_a?(Datory::Base)
119
+ instance_variables_to_hash_from(value)
120
+ else
121
+ value
122
+ end
123
+
124
+ [key.to_s.delete_prefix("@"), value]
125
+ end
126
+ end
100
127
  end
101
128
  end
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 8
6
+ MINOR = 9
7
7
  PATCH = 0
8
- PRE = nil
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.8.0
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-08-28 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
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '1.31'
89
+ - !ruby/object:Gem::Dependency
90
+ name: datory
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.1.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.1.0
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: pry
91
105
  requirement: !ruby/object:Gem::Requirement