servactory 2.15.1 → 2.16.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/servactory/actions/collection.rb +2 -1
  3. data/lib/servactory/actions/dsl.rb +1 -1
  4. data/lib/servactory/actions/stages/collection.rb +2 -1
  5. data/lib/servactory/actions/stages/stage.rb +2 -6
  6. data/lib/servactory/actions/tools/runner.rb +17 -17
  7. data/lib/servactory/configuration/actions/aliases/collection.rb +1 -0
  8. data/lib/servactory/configuration/actions/rescue_handlers/collection.rb +1 -0
  9. data/lib/servactory/configuration/actions/shortcuts/collection.rb +1 -0
  10. data/lib/servactory/configuration/collection_mode/class_names_collection.rb +1 -0
  11. data/lib/servactory/configuration/hash_mode/class_names_collection.rb +1 -0
  12. data/lib/servactory/configuration/option_helpers/option_helpers_collection.rb +1 -0
  13. data/lib/servactory/context/warehouse/inputs.rb +1 -5
  14. data/lib/servactory/context/warehouse/outputs.rb +1 -0
  15. data/lib/servactory/context/workspace/inputs.rb +1 -5
  16. data/lib/servactory/context/workspace/internals.rb +1 -4
  17. data/lib/servactory/context/workspace/outputs.rb +1 -4
  18. data/lib/servactory/info/builder.rb +24 -3
  19. data/lib/servactory/info/dsl.rb +6 -0
  20. data/lib/servactory/info/result.rb +3 -1
  21. data/lib/servactory/inputs/collection.rb +1 -0
  22. data/lib/servactory/inputs/tools/rules.rb +1 -5
  23. data/lib/servactory/inputs/tools/unnecessary.rb +1 -4
  24. data/lib/servactory/inputs/tools/validation.rb +10 -10
  25. data/lib/servactory/inputs/validations/errors.rb +1 -0
  26. data/lib/servactory/internals/collection.rb +1 -0
  27. data/lib/servactory/maintenance/attributes/options_collection.rb +2 -1
  28. data/lib/servactory/maintenance/attributes/tools/check_errors.rb +1 -0
  29. data/lib/servactory/maintenance/attributes/tools/validation.rb +4 -0
  30. data/lib/servactory/maintenance/attributes/validations/errors.rb +2 -1
  31. data/lib/servactory/outputs/collection.rb +1 -0
  32. data/lib/servactory/tool_kit/dynamic_options/inclusion.rb +3 -3
  33. data/lib/servactory/tool_kit/dynamic_options/multiple_of.rb +1 -1
  34. data/lib/servactory/utils.rb +1 -1
  35. data/lib/servactory/version.rb +2 -2
  36. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce9429e1b0d9bddfab017bae08915f91a41cf81826d54becffa3021e1fdcdb58
4
- data.tar.gz: a9d1ad2b9cd25dfd805df46df18cf4ef73d6feda77d16b0b208100b04984af29
3
+ metadata.gz: 2cff4c0f6ff8ecc7a499e738a23ba621757a674b5d1cf07707b75ac716cb3e1f
4
+ data.tar.gz: f0da2b67eb5d4e4e0126e1827182a8fd6efd659e3aa14082455fa439d163ff30
5
5
  SHA512:
6
- metadata.gz: 2a7a1d4a5356333cbec5eb3d25c11c9716cd4c56e9b15c320c572f49a58268da2ff4735706cd163c49d7d351e44daf02201fde43a0035dea9a7c8e96a6d28b74
7
- data.tar.gz: 81f5b4831820c6b944561409f2729875c021d554c880cac952a311214bf4fb05417c24e26a73f99b2104c80facc8b270b58228d3995cd753479ad3a9d3664648
6
+ metadata.gz: 44596fe29886b3685039bfd9ee7e30d38c46ae3e2c1c4ac01007919a3c497e55c70a5b275df47bf44edff9b915b5cc52ea488d9fd04fd6a90edaa535b78db5d1
7
+ data.tar.gz: 11aa49b7b0d4ddaa1de5d3ad9a2c33c6d8db4900af44b361602e994e254a0be27879f9623065cd567965077aafbfbc1c606fba0879288ebedd6895705b743773
@@ -4,7 +4,8 @@ module Servactory
4
4
  module Actions
5
5
  class Collection
6
6
  extend Forwardable
7
- def_delegators :@collection, :<<, :each, :sort_by
7
+
8
+ def_delegators :@collection, :<<, :each, :to_h, :sort_by
8
9
 
9
10
  def initialize(collection = Set.new)
10
11
  @collection = collection
@@ -77,7 +77,7 @@ module Servactory
77
77
 
78
78
  current_stage = @current_stage.presence || Stages::Stage.new(position:)
79
79
 
80
- current_stage.methods << Action.new(
80
+ current_stage.actions << Action.new(
81
81
  name,
82
82
  position:,
83
83
  **options
@@ -5,7 +5,8 @@ module Servactory
5
5
  module Stages
6
6
  class Collection
7
7
  extend Forwardable
8
- def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
8
+
9
+ def_delegators :@collection, :<<, :each, :merge, :to_h, :sort_by, :size, :empty?
9
10
 
10
11
  def initialize(collection = Set.new)
11
12
  @collection = collection
@@ -17,12 +17,8 @@ module Servactory
17
17
  @condition = condition
18
18
  end
19
19
 
20
- def next_method_position
21
- methods.size + 1
22
- end
23
-
24
- def methods
25
- @methods ||= Collection.new
20
+ def actions
21
+ @actions ||= Servactory::Actions::Collection.new
26
22
  end
27
23
  end
28
24
  end
@@ -32,17 +32,17 @@ module Servactory
32
32
 
33
33
  wrapper = stage.wrapper
34
34
  rollback = stage.rollback
35
- methods = stage.methods.sorted_by_position
35
+ actions = stage.actions.sorted_by_position
36
36
 
37
37
  if wrapper.is_a?(Proc)
38
- call_wrapper_with_methods(wrapper, rollback, methods)
38
+ call_wrapper_with_actions(wrapper, rollback, actions)
39
39
  else
40
- call_methods(methods)
40
+ call_actions(actions)
41
41
  end
42
42
  end
43
43
 
44
- def call_wrapper_with_methods(wrapper, rollback, methods) # rubocop:disable Metrics/MethodLength
45
- wrapper.call(methods: -> { call_methods(methods) }, context: @context)
44
+ def call_wrapper_with_actions(wrapper, rollback, actions) # rubocop:disable Metrics/MethodLength
45
+ wrapper.call(methods: -> { call_actions(actions) }, context: @context)
46
46
  rescue StandardError => e
47
47
  if rollback.present?
48
48
  @context.send(rollback, e)
@@ -56,16 +56,16 @@ module Servactory
56
56
  end
57
57
  end
58
58
 
59
- def call_methods(methods)
60
- methods.each do |method|
61
- next if unnecessary_for_make?(method)
59
+ def call_actions(actions)
60
+ actions.each do |action|
61
+ next if unnecessary_for_make?(action)
62
62
 
63
- call_method(method)
63
+ call_action(action)
64
64
  end
65
65
  end
66
66
 
67
- def call_method(method)
68
- @context.send(method.name)
67
+ def call_action(action)
68
+ @context.send(action.name)
69
69
  rescue StandardError => e
70
70
  rescue_with_handler(e) || raise
71
71
  end
@@ -74,21 +74,21 @@ module Servactory
74
74
  condition = stage.condition
75
75
  is_condition_opposite = stage.is_condition_opposite
76
76
 
77
- result = prepare_condition_for(condition)
77
+ result = checks_passed_for?(condition)
78
78
 
79
79
  is_condition_opposite ? !result : result
80
80
  end
81
81
 
82
- def unnecessary_for_make?(make_method)
83
- condition = make_method.condition
84
- is_condition_opposite = make_method.is_condition_opposite
82
+ def unnecessary_for_make?(make_action)
83
+ condition = make_action.condition
84
+ is_condition_opposite = make_action.is_condition_opposite
85
85
 
86
- result = prepare_condition_for(condition)
86
+ result = checks_passed_for?(condition)
87
87
 
88
88
  is_condition_opposite ? !result : result
89
89
  end
90
90
 
91
- def prepare_condition_for(condition)
91
+ def checks_passed_for?(condition)
92
92
  return false if condition.nil?
93
93
  return !Servactory::Utils.true?(condition) unless condition.is_a?(Proc)
94
94
 
@@ -6,6 +6,7 @@ module Servactory
6
6
  module Aliases
7
7
  class Collection
8
8
  extend Forwardable
9
+
9
10
  def_delegators :@collection, :<<, :merge, :include?
10
11
 
11
12
  def initialize(*)
@@ -6,6 +6,7 @@ module Servactory
6
6
  module RescueHandlers
7
7
  class Collection
8
8
  extend Forwardable
9
+
9
10
  def_delegators :@collection, :+, :detect, :reverse_each
10
11
 
11
12
  def initialize(*)
@@ -6,6 +6,7 @@ module Servactory
6
6
  module Shortcuts
7
7
  class Collection
8
8
  extend Forwardable
9
+
9
10
  def_delegators :@collection, :merge!, :fetch, :keys
10
11
 
11
12
  def initialize(*)
@@ -5,6 +5,7 @@ module Servactory
5
5
  module CollectionMode
6
6
  class ClassNamesCollection
7
7
  extend Forwardable
8
+
8
9
  def_delegators :@collection, :merge, :intersect?
9
10
 
10
11
  def initialize(collection)
@@ -5,6 +5,7 @@ module Servactory
5
5
  module HashMode
6
6
  class ClassNamesCollection
7
7
  extend Forwardable
8
+
8
9
  def_delegators :@collection, :include?, :intersect?
9
10
 
10
11
  def initialize(collection)
@@ -5,6 +5,7 @@ module Servactory
5
5
  module OptionHelpers
6
6
  class OptionHelpersCollection
7
7
  extend Forwardable
8
+
8
9
  def_delegators :@collection, :<<, :filter, :map, :find, :merge
9
10
 
10
11
  def initialize(collection = Set.new)
@@ -44,11 +44,7 @@ module Servactory
44
44
  input_name:
45
45
  )
46
46
 
47
- raise @context.class.config.input_exception_class.new(
48
- context: @context,
49
- message: message_text,
50
- input_name:
51
- )
47
+ @context.fail_input!(input_name, message: message_text)
52
48
  end
53
49
  end
54
50
  end
@@ -5,6 +5,7 @@ module Servactory
5
5
  module Warehouse
6
6
  class Outputs < Base
7
7
  extend Forwardable
8
+
8
9
  def_delegators :@arguments, :each_pair
9
10
  end
10
11
  end
@@ -68,11 +68,7 @@ module Servactory
68
68
  input_name: name
69
69
  )
70
70
 
71
- raise @context.class.config.input_exception_class.new(
72
- context: @context,
73
- message: message_text,
74
- input_name: name
75
- )
71
+ @context.fail_input!(name, message: message_text)
76
72
  end
77
73
  end
78
74
  end
@@ -80,10 +80,7 @@ module Servactory
80
80
  internal_name: name
81
81
  )
82
82
 
83
- raise @context.class.config.internal_exception_class.new(
84
- context: @context,
85
- message: message_text
86
- )
83
+ @context.fail_internal!(name, message: message_text)
87
84
  end
88
85
  end
89
86
  end
@@ -74,10 +74,7 @@ module Servactory
74
74
  output_name: name
75
75
  )
76
76
 
77
- raise @context.class.config.output_exception_class.new(
78
- context: @context,
79
- message: message_text
80
- )
77
+ @context.fail_output!(name, message: message_text)
81
78
  end
82
79
  end
83
80
  end
@@ -5,17 +5,19 @@ module Servactory
5
5
  class Builder # rubocop:disable Metrics/ClassLength
6
6
  attr_reader :inputs,
7
7
  :internals,
8
- :outputs
8
+ :outputs,
9
+ :stages
9
10
 
10
11
  def self.build(...)
11
12
  new.build(...)
12
13
  end
13
14
 
14
- def build(collection_of_inputs:, collection_of_internals:, collection_of_outputs:, config:)
15
+ def build(collection_of_inputs:, collection_of_internals:, collection_of_outputs:, collection_of_stages:, config:)
15
16
  build_all_attributes(
16
17
  inputs: collection_of_inputs,
17
18
  internals: collection_of_internals,
18
19
  outputs: collection_of_outputs,
20
+ stages: collection_of_stages,
19
21
  config:
20
22
  )
21
23
 
@@ -25,7 +27,7 @@ module Servactory
25
27
  private
26
28
 
27
29
  # rubocop:disable Metrics/MethodLength
28
- def build_all_attributes(inputs:, internals:, outputs:, config:)
30
+ def build_all_attributes(inputs:, internals:, outputs:, stages:, config:)
29
31
  build_input_attributes_with(
30
32
  collection: inputs,
31
33
  dynamic_options: config.input_option_helpers.dynamic_options
@@ -40,6 +42,8 @@ module Servactory
40
42
  collection: outputs,
41
43
  dynamic_options: config.output_option_helpers.dynamic_options
42
44
  )
45
+
46
+ build_action_stages_with(collection: stages)
43
47
  end
44
48
  # rubocop:enable Metrics/MethodLength
45
49
 
@@ -65,6 +69,23 @@ module Servactory
65
69
  )
66
70
  end
67
71
 
72
+ def build_action_stages_with(collection:) # rubocop:disable Metrics/MethodLength
73
+ @stages = collection.to_h do |stage|
74
+ [
75
+ :"stage_#{stage.position}",
76
+ stage.actions.to_h do |action|
77
+ [
78
+ action.name,
79
+ {
80
+ position: action.position,
81
+ condition: action.condition
82
+ }
83
+ ]
84
+ end
85
+ ]
86
+ end
87
+ end
88
+
68
89
  def build_attributes_with(collection:, dynamic_options:, include_specific_options: false) # rubocop:disable Metrics/MethodLength
69
90
  collection.to_h do |attribute|
70
91
  options = process_options_for(
@@ -13,11 +13,17 @@ module Servactory
13
13
  collection_of_inputs:,
14
14
  collection_of_internals:,
15
15
  collection_of_outputs:,
16
+ collection_of_stages:,
16
17
  config:
17
18
  )
18
19
 
19
20
  Result.new(builder)
20
21
  end
22
+
23
+ # API: Servactory Web
24
+ def servactory?
25
+ true
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -5,12 +5,14 @@ module Servactory
5
5
  class Result
6
6
  attr_reader :inputs,
7
7
  :internals,
8
- :outputs
8
+ :outputs,
9
+ :stages
9
10
 
10
11
  def initialize(builder)
11
12
  @inputs = builder.inputs
12
13
  @internals = builder.internals
13
14
  @outputs = builder.outputs
15
+ @stages = builder.stages
14
16
  end
15
17
  end
16
18
  end
@@ -4,6 +4,7 @@ module Servactory
4
4
  module Inputs
5
5
  class Collection
6
6
  extend Forwardable
7
+
7
8
  def_delegators :@collection, :<<, :filter, :each, :map, :flat_map, :to_h, :merge, :find
8
9
 
9
10
  def initialize(collection = Set.new)
@@ -34,11 +34,7 @@ module Servactory
34
34
  conflict_code: input.conflict_code
35
35
  )
36
36
 
37
- raise @context.class.config.input_exception_class.new(
38
- context: @context,
39
- message: message_text,
40
- input_name: input.name
41
- )
37
+ @context.fail_input!(input.name, message: message_text)
42
38
  end
43
39
  end
44
40
  end
@@ -21,10 +21,7 @@ module Servactory
21
21
  unnecessary_attributes: unnecessary_attributes.join(", ")
22
22
  )
23
23
 
24
- raise @context.class.config.input_exception_class.new(
25
- context: @context,
26
- message: message_text
27
- )
24
+ @context.fail_input!(nil, message: message_text)
28
25
  end
29
26
 
30
27
  private
@@ -29,18 +29,21 @@ module Servactory
29
29
  end
30
30
  end
31
31
 
32
- def process_option(check_key, check_options, input:)
33
- validation_classes_from(input).each do |validation_class|
32
+ def process_option(check_key, check_options, input:) # rubocop:disable Metrics/MethodLength
33
+ validation_classes = validation_classes_from(input)
34
+ return if validation_classes.empty?
35
+
36
+ validation_classes.each do |validation_class|
34
37
  errors_from_checks = process_validation_class(
35
38
  validation_class:,
36
39
  input:,
37
40
  check_key:,
38
41
  check_options:
39
- ).to_a
42
+ )
40
43
 
41
- next if errors_from_checks.empty?
44
+ next if errors_from_checks.nil? || errors_from_checks.empty?
42
45
 
43
- errors.merge(errors_from_checks)
46
+ errors.merge(errors_from_checks.to_a)
44
47
  end
45
48
  end
46
49
 
@@ -62,7 +65,7 @@ module Servactory
62
65
  ########################################################################
63
66
 
64
67
  def validation_classes_from(input)
65
- input.collection_of_options.validation_classes
68
+ @validation_classes_cache ||= input.collection_of_options.validation_classes # rubocop:disable Naming/MemoizedInstanceVariableName
66
69
  end
67
70
 
68
71
  ########################################################################
@@ -74,10 +77,7 @@ module Servactory
74
77
  def raise_errors
75
78
  return if (tmp_errors = errors.not_blank).empty?
76
79
 
77
- raise @context.class.config.input_exception_class.new(
78
- context: @context,
79
- message: tmp_errors.first
80
- )
80
+ @context.fail_input!(nil, message: tmp_errors.first)
81
81
  end
82
82
  end
83
83
  end
@@ -5,6 +5,7 @@ module Servactory
5
5
  module Validations
6
6
  class Errors
7
7
  extend Forwardable
8
+
8
9
  def_delegators :@collection, :<<, :to_a
9
10
 
10
11
  def initialize(*)
@@ -4,6 +4,7 @@ module Servactory
4
4
  module Internals
5
5
  class Collection
6
6
  extend Forwardable
7
+
7
8
  def_delegators :@collection, :<<, :filter, :each, :map, :to_h, :merge, :find
8
9
 
9
10
  def initialize(collection = Set.new)
@@ -17,7 +17,8 @@ module Servactory
17
17
  end
18
18
 
19
19
  def validation_classes
20
- filter { |option| option.validation_class.present? }
20
+ @validation_classes ||=
21
+ filter { |option| option.validation_class.present? }
21
22
  .map(&:validation_class)
22
23
  .uniq
23
24
  end
@@ -6,6 +6,7 @@ module Servactory
6
6
  module Tools
7
7
  class CheckErrors
8
8
  extend Forwardable
9
+
9
10
  def_delegators :@collection, :merge, :reject, :first, :empty?
10
11
 
11
12
  def initialize(collection = Set.new)
@@ -30,6 +30,8 @@ module Servactory
30
30
  end
31
31
 
32
32
  def process_option(check_key, check_options)
33
+ return if validation_classes.empty?
34
+
33
35
  validation_classes.each do |validation_class|
34
36
  errors_from_checks = process_validation_class(
35
37
  validation_class:,
@@ -37,6 +39,8 @@ module Servactory
37
39
  check_options:
38
40
  )
39
41
 
42
+ next if errors_from_checks.nil? || errors_from_checks.empty?
43
+
40
44
  errors.merge(errors_from_checks.to_a)
41
45
  end
42
46
  end
@@ -6,7 +6,8 @@ module Servactory
6
6
  module Validations
7
7
  class Errors
8
8
  extend Forwardable
9
- def_delegators :@collection, :<<, :to_a
9
+
10
+ def_delegators :@collection, :<<, :to_a, :empty?
10
11
 
11
12
  def initialize(*)
12
13
  @collection = Set.new
@@ -4,6 +4,7 @@ module Servactory
4
4
  module Outputs
5
5
  class Collection
6
6
  extend Forwardable
7
+
7
8
  def_delegators :@collection, :<<, :filter, :each, :map, :to_h, :merge, :find
8
9
 
9
10
  def initialize(collection = Set.new)
@@ -9,7 +9,7 @@ module Servactory
9
9
  instance.must(:be_inclusion)
10
10
  end
11
11
 
12
- def condition_for_input_with(input:, value:, option:)
12
+ def condition_for_input_with(input:, value:, option:) # rubocop:disable Naming/PredicateMethod
13
13
  if input.required? || (input.optional? && !value.nil?) # rubocop:disable Style/IfUnlessModifier
14
14
  return option.value.include?(value)
15
15
  end
@@ -21,11 +21,11 @@ module Servactory
21
21
  true
22
22
  end
23
23
 
24
- def condition_for_internal_with(value:, option:, **)
24
+ def condition_for_internal_with(value:, option:, **) # rubocop:disable Naming/PredicateMethod
25
25
  option.value.include?(value)
26
26
  end
27
27
 
28
- def condition_for_output_with(value:, option:, **)
28
+ def condition_for_output_with(value:, option:, **) # rubocop:disable Naming/PredicateMethod
29
29
  option.value.include?(value)
30
30
  end
31
31
 
@@ -20,7 +20,7 @@ module Servactory
20
20
  common_condition_with(...)
21
21
  end
22
22
 
23
- def common_condition_with(value:, option:, **)
23
+ def common_condition_with(value:, option:, **) # rubocop:disable Naming/PredicateMethod
24
24
  case value
25
25
  when Integer, Float, Rational, BigDecimal
26
26
  return false if option.value.blank?
@@ -86,7 +86,7 @@ module Servactory
86
86
  # https://github.com/rails/rails/blob/main/activerecord/lib/active_record/attribute_methods/query.rb
87
87
  # @param value [#to_s]
88
88
  # @return [Boolean]
89
- def query_attribute(value) # rubocop:disable Metrics/MethodLength
89
+ def query_attribute(value) # rubocop:disable Metrics/MethodLength, Naming/PredicateMethod
90
90
  case value
91
91
  when true then true
92
92
  when false, nil then false
@@ -3,8 +3,8 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 15
7
- PATCH = 1
6
+ MINOR = 16
7
+ PATCH = 0
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
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.15.1
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -338,7 +338,7 @@ metadata:
338
338
  documentation_uri: https://servactory.com
339
339
  source_code_uri: https://github.com/servactory/servactory
340
340
  bug_tracker_uri: https://github.com/servactory/servactory/issues
341
- changelog_uri: https://github.com/servactory/servactory/blob/master/CHANGELOG.md
341
+ changelog_uri: https://github.com/servactory/servactory/blob/main/CHANGELOG.md
342
342
  rubygems_mfa_required: 'true'
343
343
  rdoc_options: []
344
344
  require_paths: