servactory 2.6.0.rc3 → 2.6.0.rc5

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: 3681e7c5a5e02756f7df77333a0974264548b6060605073f02cdbe8a2c3d9f55
4
- data.tar.gz: 63b0ea14ade5b473b44173832c3411a3ac0d12e52e87539b8c7a5200f4a86915
3
+ metadata.gz: 644c141dd6e3bdee996ffc4aad56a6e9b472ad964406923cc14fd1185541e2ae
4
+ data.tar.gz: 4036bed062dd8717f6288c72c498cca4a2a91401154a23266148a42cac2aa10a
5
5
  SHA512:
6
- metadata.gz: cd344cbcfa248de3a6974b8fa28e5544678851a2d7bf11fa3964087fbf80bc54551450d654624477ff5cfd9f7d7705b69507e2ee6e2ab46450adf7616c331ebd
7
- data.tar.gz: dfefd697f5808b020e0507748f97c96e2a674dbf8a04707943a39f6a220a26f1002a6eb47fee727e4cb04ee042b23b87e4cf98804b52b2a22859eea73ac59037
6
+ metadata.gz: '09e7437eedd68dc0c14a98ec4c6c5c922483fc9e3924425a0478bb8d1404c36ef0531fb2adb9d2094ff7fa20633f92fb44fa8bd5588c6d7b28372371fe709af8'
7
+ data.tar.gz: ac82354cffdb531261d50a12f0a54fb79bca2474fcf00b9851769ebcbe2a08c9c46fbb8edfb07bb8964142adac85e901d6773082001ffc0248746e8c448b77a1
@@ -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,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Configuration
5
+ class ClassNamesCollection
6
+ extend Forwardable
7
+ def_delegators :@collection, :merge, :intersection
8
+
9
+ def initialize(collection)
10
+ @collection = collection
11
+ end
12
+ end
13
+ end
14
+ 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
@@ -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,6 +30,9 @@ module Servactory
29
30
 
30
31
  @result_class = Servactory::Result
31
32
 
33
+ @collection_mode_class_names =
34
+ Servactory::Configuration::ClassNamesCollection.new(default_collection_mode_class_names)
35
+
32
36
  @hash_mode_class_names =
33
37
  Servactory::Maintenance::HashMode::ClassNamesCollection.new(default_hash_mode_class_names)
34
38
 
@@ -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
@@ -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,38 @@ 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?
31
+ return [false, :wrong_type] if @collection_mode_class_names.intersection(attribute.types).empty?
32
+
33
+ values = value.respond_to?(:flatten) ? value&.flatten : value
29
34
 
30
- validate_for!(values: value, option: option)
35
+ validate_for!(attribute: attribute, values: values, option: option)
31
36
  end
32
37
 
33
- def validate_for!(values:, option:) # rubocop:disable Metrics/CyclomaticComplexity
38
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
+ def validate_for!(attribute:, values:, option:)
34
40
  consists_of_types = Array(option.value)
35
41
 
36
- return [false, :required] if !consists_of_types.include?(NilClass) && !values&.flatten&.all?(&:present?)
42
+ if !consists_of_types.include?(NilClass) && !values&.all?(&:present?) &&
43
+ (
44
+ (
45
+ attribute.input? && (
46
+ (values.blank? && attribute.required?) ||
47
+ (values.present? && attribute.required?)
48
+ )
49
+ ) || attribute.internal? || attribute.output?
50
+ )
51
+ return [false, :required]
52
+ end
37
53
 
38
- return true if values.flatten.all? do |value|
54
+ return true if values.blank? && attribute.input? && attribute.optional?
55
+
56
+ return true if values.all? do |value|
39
57
  consists_of_types.include?(value.class)
40
58
  end
41
59
 
42
- [false, :wrong_type]
60
+ [false, :wrong_element_type]
43
61
  end
62
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
44
63
 
45
64
  ########################################################################
46
65
 
@@ -84,9 +103,11 @@ module Servactory
84
103
  end
85
104
 
86
105
  def given_type_for(values:, option_value:)
87
- return nil if values.nil?
106
+ return "NilClass" if values.nil?
107
+
108
+ values = values&.flatten if values.respond_to?(:flatten)
88
109
 
89
- values.flatten.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
110
+ values.filter { |value| Array(option_value).exclude?(value.class) }.map(&:class).uniq.join(", ")
90
111
  end
91
112
  end
92
113
  end
@@ -5,7 +5,7 @@ module Servactory
5
5
  MAJOR = 2
6
6
  MINOR = 6
7
7
  PATCH = 0
8
- PRE = "rc3"
8
+ PRE = "rc5"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0.rc3
4
+ version: 2.6.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -256,6 +256,7 @@ files:
256
256
  - lib/servactory/actions/tools/runner.rb
257
257
  - lib/servactory/actions/workspace.rb
258
258
  - lib/servactory/base.rb
259
+ - lib/servactory/configuration/class_names_collection.rb
259
260
  - lib/servactory/configuration/dsl.rb
260
261
  - lib/servactory/configuration/factory.rb
261
262
  - lib/servactory/configuration/setup.rb