servactory 2.6.0.rc4 → 2.6.0

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: 53d70d5438c6e58daf86d416c2910eabe04727880af9189b7813da17bd3bb777
4
- data.tar.gz: cbab6d80c1d012d80d72f5f76eaa3fd17d01af568961d0eaf16a80abfc61591a
3
+ metadata.gz: 0df96b35bd963790408ba89eb4c6d80b7b19c4edc869ceade70f0d9d660f41ce
4
+ data.tar.gz: 97c287969f8358a77903d17b79624b59a06abd8aa94aa469e5d458f99ae50342
5
5
  SHA512:
6
- metadata.gz: 2ec8ed69eaa089a441280c3f0650b842509175f9d14b25a2f838fd61e4e60ca622e24e65a76d7303f8b041f070eb6cd17f51cb959b1ceef9f809cadbe8e4d492
7
- data.tar.gz: d96fd4a4a3864a4654e80802451ee003cffc5e3d609d368667790fea4c1511162de0f06491906d9e7e49e3f878c72cda870b28848150b01c84a6eb92df2d325f
6
+ metadata.gz: 57caa41f80f9df2fa40061dad1337839dfba5dcc69b54e44ac8651bb83ec4e4d034870e7cd78f1d23661cd4ab66153904ed9679e78253a91e5532a7c596f4f11
7
+ data.tar.gz: 9e85fcb8bd9994756b6d9519d1a2bbbc68a7bd13254505ae4930552d377a011eb233d70e7fe9abdb23cc52d0f8812294bfb70ce15b5f34b6861cbf763c918461
@@ -20,7 +20,8 @@ en:
20
20
  dynamic_options:
21
21
  consists_of:
22
22
  required: "[%{service_class_name}] Required element in input collection `%{input_name}` is missing"
23
- wrong_type: "[%{service_class_name}] Wrong element type in input collection `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
23
+ wrong_type: "[%{service_class_name}] Wrong input collection type `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
24
+ wrong_element_type: "[%{service_class_name}] Wrong element type in input collection `%{input_name}`, expected `%{expected_type}`, got `%{given_type}`"
24
25
  format:
25
26
  default: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
26
27
  wrong_pattern: "[%{service_class_name}] Input `%{input_name}` does not match `%{format_name}` format"
@@ -55,7 +56,8 @@ en:
55
56
  dynamic_options:
56
57
  consists_of:
57
58
  required: "[%{service_class_name}] Required element in internal attribute collection `%{internal_name}` is missing"
58
- wrong_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
59
+ wrong_type: "[%{service_class_name}] Wrong internal attribute collection type `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
60
+ wrong_element_type: "[%{service_class_name}] Wrong element type in internal attribute collection `%{internal_name}`, expected `%{expected_type}`, got `%{given_type}`"
59
61
  format:
60
62
  default: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
61
63
  wrong_pattern: "[%{service_class_name}] Internal attribute `%{internal_name}` does not match `%{format_name}` format"
@@ -82,7 +84,8 @@ en:
82
84
  dynamic_options:
83
85
  consists_of:
84
86
  required: "[%{service_class_name}] Required element in output attribute collection `%{output_name}` is missing"
85
- wrong_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
87
+ wrong_type: "[%{service_class_name}] Wrong output attribute collection type `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
88
+ wrong_element_type: "[%{service_class_name}] Wrong element type in output attribute collection `%{output_name}`, expected `%{expected_type}`, got `%{given_type}`"
86
89
  format:
87
90
  default: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
88
91
  wrong_pattern: "[%{service_class_name}] Output attribute `%{output_name}` does not match `%{format_name}` format"
@@ -20,7 +20,8 @@ ru:
20
20
  dynamic_options:
21
21
  consists_of:
22
22
  required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции инпута `%{input_name}`"
23
- wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
23
+ wrong_type: "[%{service_class_name}] Неправильный тип коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
24
+ wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции инпута `%{input_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
24
25
  format:
25
26
  default: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
26
27
  wrong_pattern: "[%{service_class_name}] Инпут `%{input_name}` не соответствует формату `%{format_name}`"
@@ -55,7 +56,8 @@ ru:
55
56
  dynamic_options:
56
57
  consists_of:
57
58
  required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции внутреннего атрибута `%{internal_name}`"
58
- wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
59
+ wrong_type: "[%{service_class_name}] Неправильный тип коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
60
+ wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции внутреннего атрибута `%{internal_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
59
61
  format:
60
62
  default: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
61
63
  wrong_pattern: "[%{service_class_name}] Внутренний атрибут `%{internal_name}` не соответствует формату `%{format_name}`"
@@ -82,7 +84,8 @@ ru:
82
84
  dynamic_options:
83
85
  consists_of:
84
86
  required: "[%{service_class_name}] Отсутствует обязательный элемент в коллекции выходящего атрибута `%{output_name}`"
85
- wrong_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
87
+ wrong_type: "[%{service_class_name}] Неправильный тип коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
88
+ wrong_element_type: "[%{service_class_name}] Неправильный тип элемента в коллекции выходящего атрибута `%{output_name}`, ожидалось `%{expected_type}`, получено `%{given_type}`"
86
89
  format:
87
90
  default: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
88
91
  wrong_pattern: "[%{service_class_name}] Выходящий атрибут `%{output_name}` не соответствует формату `%{format_name}`"
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Configuration
5
+ module Actions
6
+ module Aliases
7
+ class Collection
8
+ extend Forwardable
9
+ def_delegators :@collection, :<<, :merge, :include?
10
+
11
+ def initialize(*)
12
+ @collection = Set.new
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Configuration
5
+ module Actions
6
+ module RescueHandlers
7
+ class Collection
8
+ extend Forwardable
9
+ def_delegators :@collection, :+, :detect, :reverse_each
10
+
11
+ def initialize(*)
12
+ @collection = Set.new
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Configuration
5
+ module Actions
6
+ module Shortcuts
7
+ class Collection
8
+ extend Forwardable
9
+ def_delegators :@collection, :<<, :each, :merge, :include?
10
+
11
+ def initialize(*)
12
+ @collection = Set.new
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Configuration
5
+ module CollectionMode
6
+ class ClassNamesCollection
7
+ extend Forwardable
8
+ def_delegators :@collection, :merge, :intersection
9
+
10
+ def initialize(collection)
11
+ @collection = collection
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -20,6 +20,8 @@ module Servactory
20
20
 
21
21
  child.config.result_class = config.result_class
22
22
 
23
+ child.config.collection_mode_class_names = config.collection_mode_class_names
24
+
23
25
  child.config.input_option_helpers = config.input_option_helpers
24
26
  child.config.internal_option_helpers = config.internal_option_helpers
25
27
  child.config.output_option_helpers = config.output_option_helpers
@@ -69,6 +69,10 @@ module Servactory
69
69
  raise_error_about_wrong_result_class_with(:result_class, result_class)
70
70
  end
71
71
 
72
+ def collection_mode_class_names(collection_mode_class_names)
73
+ @config.collection_mode_class_names.merge(collection_mode_class_names)
74
+ end
75
+
72
76
  def hash_mode_class_names(hash_mode_class_names)
73
77
  @config.hash_mode_class_names.merge(hash_mode_class_names)
74
78
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Maintenance
4
+ module Configuration
5
5
  module HashMode
6
6
  class ClassNamesCollection
7
7
  extend Forwardable
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Servactory
4
- module Maintenance
5
- module Attributes
4
+ module Configuration
5
+ module OptionHelpers
6
6
  class OptionHelpersCollection
7
7
  extend Forwardable
8
8
  def_delegators :@collection, :<<, :find, :merge
@@ -9,6 +9,7 @@ module Servactory
9
9
  :success_class,
10
10
  :failure_class,
11
11
  :result_class,
12
+ :collection_mode_class_names,
12
13
  :hash_mode_class_names,
13
14
  :input_option_helpers,
14
15
  :internal_option_helpers,
@@ -29,21 +30,24 @@ module Servactory
29
30
 
30
31
  @result_class = Servactory::Result
31
32
 
33
+ @collection_mode_class_names =
34
+ Servactory::Configuration::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
35
+
32
36
  @hash_mode_class_names =
33
- Servactory::Maintenance::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
37
+ Servactory::Configuration::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
34
38
 
35
39
  @input_option_helpers =
36
- Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_input_option_helpers)
40
+ Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_input_option_helpers)
37
41
 
38
42
  @internal_option_helpers =
39
- Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_internal_option_helpers)
43
+ Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_internal_option_helpers)
40
44
 
41
45
  @output_option_helpers =
42
- Servactory::Maintenance::Attributes::OptionHelpersCollection.new(default_output_option_helpers)
46
+ Servactory::Configuration::OptionHelpers::OptionHelpersCollection.new(default_output_option_helpers)
43
47
 
44
- @action_aliases = Servactory::Actions::Aliases::Collection.new
45
- @action_shortcuts = Servactory::Actions::Shortcuts::Collection.new
46
- @action_rescue_handlers = Servactory::Actions::RescueHandlers::Collection.new
48
+ @action_aliases = Servactory::Configuration::Actions::Aliases::Collection.new
49
+ @action_shortcuts = Servactory::Configuration::Actions::Shortcuts::Collection.new
50
+ @action_rescue_handlers = Servactory::Configuration::Actions::RescueHandlers::Collection.new
47
51
 
48
52
  @i18n_root_key = "servactory"
49
53
 
@@ -56,6 +60,10 @@ module Servactory
56
60
 
57
61
  private
58
62
 
63
+ def default_collection_mode_class_names
64
+ Set[Array, Set]
65
+ end
66
+
59
67
  def default_hash_mode_class_names
60
68
  Set[Hash]
61
69
  end
@@ -63,19 +71,19 @@ module Servactory
63
71
  def default_input_option_helpers
64
72
  Set[
65
73
  Servactory::Maintenance::Attributes::OptionHelper.new(name: :optional, equivalent: { required: false }),
66
- Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
74
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names: collection_mode_class_names)
67
75
  ]
68
76
  end
69
77
 
70
78
  def default_internal_option_helpers
71
79
  Set[
72
- Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
80
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names: collection_mode_class_names)
73
81
  ]
74
82
  end
75
83
 
76
84
  def default_output_option_helpers
77
85
  Set[
78
- Servactory::ToolKit::DynamicOptions::ConsistsOf.setup
86
+ Servactory::ToolKit::DynamicOptions::ConsistsOf.use(collection_mode_class_names: collection_mode_class_names)
79
87
  ]
80
88
  end
81
89
  end
@@ -142,10 +142,13 @@ module Servactory
142
142
  value: wrong_value
143
143
  )
144
144
  elsif input_required_message.is_a?(Proc)
145
+ service_class = Struct.new(:class_name, keyword_init: true)
146
+ service = service_class.new(class_name: described_class.name)
147
+
145
148
  input_work = attribute_data.fetch(:work)
146
149
 
147
150
  input_required_message = input_required_message.call(
148
- service_class_name: described_class.name,
151
+ service: service,
149
152
  input: input_work,
150
153
  value: wrong_value
151
154
  )
@@ -4,11 +4,14 @@ module Servactory
4
4
  module ToolKit
5
5
  module DynamicOptions
6
6
  class ConsistsOf < Must
7
- COLLECTION_CLASS_NAMES = [Array, Set].freeze
8
- private_constant :COLLECTION_CLASS_NAMES
7
+ def self.use(option_name = :consists_of, collection_mode_class_names:)
8
+ instance = new(option_name, :type, false)
9
+ instance.assign(collection_mode_class_names)
10
+ instance.must(:consists_of)
11
+ end
9
12
 
10
- def self.setup(option_name = :consists_of)
11
- new(option_name, :type, false).must(:consists_of)
13
+ def assign(collection_mode_class_names)
14
+ @collection_mode_class_names = collection_mode_class_names
12
15
  end
13
16
 
14
17
  def condition_for_input_with(input:, value:, option:)
@@ -25,22 +28,39 @@ module Servactory
25
28
 
26
29
  def common_condition_with(attribute:, value:, option:)
27
30
  return true if option.value == false
28
- return false if COLLECTION_CLASS_NAMES.intersection(attribute.types).empty?
29
- return true if attribute.input? && attribute.optional? && value.blank?
31
+ return [false, :wrong_type] if @collection_mode_class_names.intersection(attribute.types).empty?
32
+
33
+ values = value.respond_to?(:flatten) ? value&.flatten : value
30
34
 
31
- validate_for!(values: value, option: option)
35
+ validate_for!(attribute: attribute, values: values, option: option)
32
36
  end
33
37
 
34
- def validate_for!(values:, option:) # rubocop:disable Metrics/CyclomaticComplexity
38
+ def validate_for!(attribute:, values:, option:)
35
39
  consists_of_types = Array(option.value)
36
40
 
37
- return [false, :required] if !consists_of_types.include?(NilClass) && !values&.flatten&.all?(&:present?)
41
+ if fails_presence_validation?(attribute: attribute, values: values, consists_of_types: consists_of_types)
42
+ return [false, :required]
43
+ end
38
44
 
39
- return true if values.flatten.all? do |value|
45
+ return true if values.blank? && attribute.input? && attribute.optional?
46
+
47
+ return true if values.all? do |value|
40
48
  consists_of_types.include?(value.class)
41
49
  end
42
50
 
43
- [false, :wrong_type]
51
+ [false, :wrong_element_type]
52
+ end
53
+
54
+ def fails_presence_validation?(attribute:, values:, consists_of_types:)
55
+ return false if consists_of_types.include?(NilClass)
56
+
57
+ check_present = proc { _1 && !values.all?(&:present?) }
58
+
59
+ [
60
+ check_present[attribute.input? && (attribute.required? || (attribute.optional? && values.present?))],
61
+ check_present[attribute.internal?],
62
+ check_present[attribute.output?]
63
+ ].any?
44
64
  end
45
65
 
46
66
  ########################################################################
@@ -85,9 +105,11 @@ module Servactory
85
105
  end
86
106
 
87
107
  def given_type_for(values:, option_value:)
88
- return nil if values.nil?
108
+ return "NilClass" if values.nil?
109
+
110
+ values = values&.flatten if values.respond_to?(:flatten)
89
111
 
90
- values.flatten.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
112
+ values.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
91
113
  end
92
114
  end
93
115
  end
@@ -5,7 +5,7 @@ module Servactory
5
5
  MAJOR = 2
6
6
  MINOR = 6
7
7
  PATCH = 0
8
- PRE = "rc4"
8
+ PRE = nil
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.6.0.rc4
4
+ version: 2.6.0
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-05-11 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -245,19 +245,22 @@ files:
245
245
  - lib/generators/servactory/templates/services/application_service/result.rb
246
246
  - lib/servactory.rb
247
247
  - lib/servactory/actions/action.rb
248
- - lib/servactory/actions/aliases/collection.rb
249
248
  - lib/servactory/actions/collection.rb
250
249
  - lib/servactory/actions/dsl.rb
251
- - lib/servactory/actions/rescue_handlers/collection.rb
252
- - lib/servactory/actions/shortcuts/collection.rb
253
250
  - lib/servactory/actions/stages/collection.rb
254
251
  - lib/servactory/actions/stages/stage.rb
255
252
  - lib/servactory/actions/tools/rules.rb
256
253
  - lib/servactory/actions/tools/runner.rb
257
254
  - lib/servactory/actions/workspace.rb
258
255
  - lib/servactory/base.rb
256
+ - lib/servactory/configuration/actions/aliases/collection.rb
257
+ - lib/servactory/configuration/actions/rescue_handlers/collection.rb
258
+ - lib/servactory/configuration/actions/shortcuts/collection.rb
259
+ - lib/servactory/configuration/collection_mode/class_names_collection.rb
259
260
  - lib/servactory/configuration/dsl.rb
260
261
  - lib/servactory/configuration/factory.rb
262
+ - lib/servactory/configuration/hash_mode/class_names_collection.rb
263
+ - lib/servactory/configuration/option_helpers/option_helpers_collection.rb
261
264
  - lib/servactory/configuration/setup.rb
262
265
  - lib/servactory/context/callable.rb
263
266
  - lib/servactory/context/dsl.rb
@@ -298,7 +301,6 @@ files:
298
301
  - lib/servactory/maintenance/attributes/define_method.rb
299
302
  - lib/servactory/maintenance/attributes/option.rb
300
303
  - lib/servactory/maintenance/attributes/option_helper.rb
301
- - lib/servactory/maintenance/attributes/option_helpers_collection.rb
302
304
  - lib/servactory/maintenance/attributes/options/registrar.rb
303
305
  - lib/servactory/maintenance/attributes/options_collection.rb
304
306
  - lib/servactory/maintenance/attributes/tools/check_errors.rb
@@ -311,7 +313,6 @@ files:
311
313
  - lib/servactory/maintenance/attributes/validations/inclusion.rb
312
314
  - lib/servactory/maintenance/attributes/validations/must.rb
313
315
  - lib/servactory/maintenance/attributes/validations/type.rb
314
- - lib/servactory/maintenance/hash_mode/class_names_collection.rb
315
316
  - lib/servactory/maintenance/validations/object_schema.rb
316
317
  - lib/servactory/maintenance/validations/types.rb
317
318
  - lib/servactory/outputs/collection.rb
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Actions
5
- module Aliases
6
- class Collection
7
- extend Forwardable
8
- def_delegators :@collection, :<<, :merge, :include?
9
-
10
- def initialize(*)
11
- @collection = Set.new
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Actions
5
- module RescueHandlers
6
- class Collection
7
- extend Forwardable
8
- def_delegators :@collection, :+, :detect, :reverse_each
9
-
10
- def initialize(*)
11
- @collection = Set.new
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Actions
5
- module Shortcuts
6
- class Collection
7
- extend Forwardable
8
- def_delegators :@collection, :<<, :each, :merge, :include?
9
-
10
- def initialize(*)
11
- @collection = Set.new
12
- end
13
- end
14
- end
15
- end
16
- end