servactory 2.15.1 → 2.16.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: ce9429e1b0d9bddfab017bae08915f91a41cf81826d54becffa3021e1fdcdb58
4
- data.tar.gz: a9d1ad2b9cd25dfd805df46df18cf4ef73d6feda77d16b0b208100b04984af29
3
+ metadata.gz: 3ff6af883d52092f1fd6589a77d962a3bd8b346ca5b8f40ffe4489b993e023e3
4
+ data.tar.gz: 8eb05b74076fa1c75e6688ffa1503daaca3f5f0a43d32d621eeda3912456d4cc
5
5
  SHA512:
6
- metadata.gz: 2a7a1d4a5356333cbec5eb3d25c11c9716cd4c56e9b15c320c572f49a58268da2ff4735706cd163c49d7d351e44daf02201fde43a0035dea9a7c8e96a6d28b74
7
- data.tar.gz: 81f5b4831820c6b944561409f2729875c021d554c880cac952a311214bf4fb05417c24e26a73f99b2104c80facc8b270b58228d3995cd753479ad3a9d3664648
6
+ metadata.gz: 9bf62d2f5546ccf038ba21009e9cca29d27dfe10431d1117bd020e5c537d45afc10f1323b2ce34ae87b7e43d750b4cae767277390d51de81c3692fe984fb7aaf
7
+ data.tar.gz: 0c1c762bccd20fc0d9738a6c5788dd27d874567306adeb6edabe5d2ba0522fdabd0c507ac97d63ca9b35dba7fa4475ff9c54c6ffdb76ebd819e58d092e9acf98
@@ -4,7 +4,7 @@ module Servactory
4
4
  module Actions
5
5
  class Collection
6
6
  extend Forwardable
7
- def_delegators :@collection, :<<, :each, :sort_by
7
+ def_delegators :@collection, :<<, :each, :map, :sort_by
8
8
 
9
9
  def initialize(collection = Set.new)
10
10
  @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,7 @@ 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
+ def_delegators :@collection, :<<, :each, :merge, :to_h, :sort_by, :size, :empty?
9
9
 
10
10
  def initialize(collection = Set.new)
11
11
  @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
@@ -79,9 +79,9 @@ module Servactory
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
86
  result = prepare_condition_for(condition)
87
87
 
@@ -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
@@ -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,22 @@ 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.map do |action|
77
+ {
78
+ action.name => {
79
+ position: action.position,
80
+ condition: action.condition
81
+ }
82
+ }
83
+ end
84
+ ]
85
+ end
86
+ end
87
+
68
88
  def build_attributes_with(collection:, dynamic_options:, include_specific_options: false) # rubocop:disable Metrics/MethodLength
69
89
  collection.to_h do |attribute|
70
90
  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
@@ -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
@@ -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
@@ -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,7 @@ module Servactory
6
6
  module Validations
7
7
  class Errors
8
8
  extend Forwardable
9
- def_delegators :@collection, :<<, :to_a
9
+ def_delegators :@collection, :<<, :to_a, :empty?
10
10
 
11
11
  def initialize(*)
12
12
  @collection = Set.new
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 15
7
- PATCH = 1
8
- PRE = nil
6
+ MINOR = 16
7
+ PATCH = 0
8
+ PRE = "rc2"
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.15.1
4
+ version: 2.16.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov