servactory 2.2.3 → 2.3.1

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: a51453d18412c6b59e5bf08eafdc54c5bf30d5f174b3f0bac9f765f86ce571d3
4
- data.tar.gz: 2c808474f78bc6de5305768c95ed8da3b235c25f51bdf03b8f88e824aa25ad9d
3
+ metadata.gz: 9598623fa8187288fe92566315cf8bf293f0fec4995cd778186b7b29bba90504
4
+ data.tar.gz: 03d3236b8b846e1fecc11ee19d754a235c5b40a9b7d58f36298767a2ea36b241
5
5
  SHA512:
6
- metadata.gz: 2868a096dd3b76d8bcc5ee718220c7335abbab1b5d9423260b0d0e84e258bf97cf2b737976a625d6bed4ef0dbbfc036bb26f9aadfc7ebf208fedd97c797cad47
7
- data.tar.gz: fb248ceeaf20d9d4945b7e0872d3c069416379f650afca902910d324747c03d98dce46330283ae67466a1cc79651225903ef53075b3d5c3295023fd3ac883c84
6
+ metadata.gz: 9a56ab102855338ee035e6b4163af6e39d618ea56c3a8277b9f6bae7c5974d203ade30db911ed32a0cad0c541e8f2b3e7dced9fb7015ee905e0e15ef66b06094
7
+ data.tar.gz: c2d2014270e95e382de071858c8ce43f555c6b05d019f24b30f824fad934c63cd849b837813dbe53faf5afde8b6da4cb32d5f7ee72c6074ccc275d4a2a0dc453
@@ -11,9 +11,9 @@ module Servactory
11
11
  def inherited(child) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
12
  super
13
13
 
14
- child.config.input_error_class = config.input_error_class
15
- child.config.internal_error_class = config.internal_error_class
16
- child.config.output_error_class = config.output_error_class
14
+ child.config.input_exception_class = config.input_exception_class
15
+ child.config.internal_exception_class = config.internal_exception_class
16
+ child.config.output_exception_class = config.output_exception_class
17
17
 
18
18
  child.config.success_class = config.success_class
19
19
  child.config.failure_class = config.failure_class
@@ -7,20 +7,60 @@ module Servactory
7
7
  @config = config
8
8
  end
9
9
 
10
+ # DEPRECATED: These configs must be deleted after release 2.4.
10
11
  def input_error_class(input_error_class)
11
- @config.input_error_class = input_error_class
12
+ Kernel.warn "DEPRECATION WARNING: " \
13
+ "Configuration `input_error_class` is deprecated; " \
14
+ "use `internal_exception_class` instead. " \
15
+ "It will be removed in one of the next releases."
16
+
17
+ input_exception_class(input_error_class)
18
+ end
19
+
20
+ # DEPRECATED: These configs must be deleted after release 2.4.
21
+ def internal_error_class(internal_error_class)
22
+ Kernel.warn "DEPRECATION WARNING: " \
23
+ "Configuration `internal_error_class` is deprecated; " \
24
+ "use `internal_exception_class` instead. " \
25
+ "It will be removed in one of the next releases."
26
+
27
+ internal_exception_class(internal_error_class)
12
28
  end
13
29
 
30
+ # DEPRECATED: These configs must be deleted after release 2.4.
14
31
  def output_error_class(output_error_class)
15
- @config.output_error_class = output_error_class
32
+ Kernel.warn "DEPRECATION WARNING: " \
33
+ "Configuration `output_error_class` is deprecated; " \
34
+ "use `output_exception_class` instead. " \
35
+ "It will be removed in one of the next releases."
36
+
37
+ output_exception_class(output_error_class)
16
38
  end
17
39
 
18
- def internal_error_class(internal_error_class)
19
- @config.internal_error_class = internal_error_class
40
+ def input_exception_class(input_exception_class)
41
+ return @config.input_exception_class = input_exception_class if subclass_of_exception?(input_exception_class)
42
+
43
+ raise_error_about_wrong_exception_class_with(:input_exception_class, input_exception_class)
44
+ end
45
+
46
+ def internal_exception_class(internal_exception_class)
47
+ if subclass_of_exception?(internal_exception_class)
48
+ return @config.internal_exception_class = internal_exception_class
49
+ end
50
+
51
+ raise_error_about_wrong_exception_class_with(:internal_exception_class, internal_exception_class)
52
+ end
53
+
54
+ def output_exception_class(output_exception_class)
55
+ return @config.output_exception_class = output_exception_class if subclass_of_exception?(output_exception_class)
56
+
57
+ raise_error_about_wrong_exception_class_with(:output_exception_class, output_exception_class)
20
58
  end
21
59
 
22
60
  def failure_class(failure_class)
23
- @config.failure_class = failure_class
61
+ return @config.failure_class = failure_class if subclass_of_exception?(failure_class)
62
+
63
+ raise_error_about_wrong_exception_class_with(:failure_class, failure_class)
24
64
  end
25
65
 
26
66
  def collection_mode_class_names(collection_mode_class_names)
@@ -50,6 +90,21 @@ module Servactory
50
90
  def action_shortcuts(action_shortcuts)
51
91
  @config.action_shortcuts.merge(action_shortcuts)
52
92
  end
93
+
94
+ ##########################################################################
95
+
96
+ def subclass_of_exception?(value)
97
+ value.is_a?(Class) && value <= Exception
98
+ end
99
+
100
+ ##########################################################################
101
+
102
+ def raise_error_about_wrong_exception_class_with(config_name, value)
103
+ raise ArgumentError,
104
+ "Error in `#{config_name}` configuration. " \
105
+ "The `#{value}` value must be a subclass of `Exception`. " \
106
+ "See example configuration here: https://servactory.com/guide/configuration"
107
+ end
53
108
  end
54
109
  end
55
110
  end
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  module Configuration
5
5
  class Setup
6
- attr_accessor :input_error_class,
7
- :internal_error_class,
8
- :output_error_class,
6
+ attr_accessor :input_exception_class,
7
+ :internal_exception_class,
8
+ :output_exception_class,
9
9
  :success_class,
10
10
  :failure_class,
11
11
  :collection_mode_class_names,
@@ -17,12 +17,12 @@ module Servactory
17
17
  :action_shortcuts
18
18
 
19
19
  def initialize # rubocop:disable Metrics/MethodLength
20
- @input_error_class = Servactory::Errors::InputError
21
- @internal_error_class = Servactory::Errors::InternalError
22
- @output_error_class = Servactory::Errors::OutputError
20
+ @input_exception_class = Servactory::Exceptions::Input
21
+ @internal_exception_class = Servactory::Exceptions::Internal
22
+ @output_exception_class = Servactory::Exceptions::Output
23
23
 
24
24
  @success_class = Servactory::Exceptions::Success
25
- @failure_class = Servactory::Errors::Failure
25
+ @failure_class = Servactory::Exceptions::Failure
26
26
 
27
27
  @collection_mode_class_names =
28
28
  Servactory::Maintenance::CollectionMode::ClassNamesCollection.new(default_collection_mode_class_names)
@@ -21,7 +21,20 @@ module Servactory
21
21
  end
22
22
 
23
23
  def call(arguments = {})
24
- call!(arguments)
24
+ context = send(:new)
25
+
26
+ context.send(
27
+ :_call!,
28
+ incoming_arguments: arguments.symbolize_keys,
29
+ collection_of_inputs: collection_of_inputs,
30
+ collection_of_internals: collection_of_internals,
31
+ collection_of_outputs: collection_of_outputs,
32
+ collection_of_stages: collection_of_stages
33
+ )
34
+
35
+ Servactory::Result.success_for(context: context)
36
+ rescue config.success_class => e
37
+ Servactory::Result.success_for(context: e.context)
25
38
  rescue config.failure_class => e
26
39
  Servactory::Result.failure_for(exception: e)
27
40
  end
@@ -104,7 +104,7 @@ module Servactory
104
104
  input_name: name
105
105
  )
106
106
 
107
- raise @context.class.config.input_error_class.new(message: message_text, input_name: name)
107
+ raise @context.class.config.input_exception_class.new(message: message_text, input_name: name)
108
108
  end
109
109
  end
110
110
  end
@@ -75,7 +75,7 @@ module Servactory
75
75
  internal_name: name
76
76
  )
77
77
 
78
- raise @context.class.config.input_error_class.new(message: message_text)
78
+ raise @context.class.config.input_exception_class.new(message: message_text)
79
79
  end
80
80
  end
81
81
  end
@@ -75,7 +75,7 @@ module Servactory
75
75
  output_name: name
76
76
  )
77
77
 
78
- raise @context.class.config.output_error_class.new(message: message_text)
78
+ raise @context.class.config.output_exception_class.new(message: message_text)
79
79
  end
80
80
  end
81
81
  end
@@ -30,21 +30,21 @@ module Servactory
30
30
  end
31
31
 
32
32
  def fail_input!(input_name, message:)
33
- raise self.class.config.input_error_class.new(
33
+ raise self.class.config.input_exception_class.new(
34
34
  input_name: input_name,
35
35
  message: message
36
36
  )
37
37
  end
38
38
 
39
39
  def fail_internal!(internal_name, message:)
40
- raise self.class.config.internal_error_class.new(
40
+ raise self.class.config.internal_exception_class.new(
41
41
  internal_name: internal_name,
42
42
  message: message
43
43
  )
44
44
  end
45
45
 
46
46
  def fail_output!(output_name, message:)
47
- raise self.class.config.output_error_class.new(
47
+ raise self.class.config.output_exception_class.new(
48
48
  output_name: output_name,
49
49
  message: message
50
50
  )
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Errors
5
+ # DEPRECATED: This class will be deleted after release 2.4.
5
6
  class Failure < Servactory::Exceptions::Base
6
7
  attr_reader :type,
7
8
  :message,
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Errors
5
+ # DEPRECATED: This class will be deleted after release 2.4.
5
6
  class InputError < Servactory::Exceptions::Base
6
7
  attr_reader :message,
7
8
  :input_name
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Errors
5
+ # DEPRECATED: This class will be deleted after release 2.4.
5
6
  class InternalError < Servactory::Exceptions::Base
6
7
  attr_reader :message,
7
8
  :internal_name
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Errors
5
+ # DEPRECATED: This class will be deleted after release 2.4.
5
6
  class OutputError < Servactory::Exceptions::Base
6
7
  attr_reader :message,
7
8
  :output_name
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Exceptions
5
+ class Failure < Base
6
+ attr_reader :type,
7
+ :message,
8
+ :meta
9
+
10
+ def initialize(type: :base, message:, meta: nil) # rubocop:disable Style/KeywordParametersOrder
11
+ @type = type
12
+ @message = message
13
+ @meta = meta
14
+
15
+ super(message)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Exceptions
5
+ class Input < Base
6
+ attr_reader :message,
7
+ :input_name
8
+
9
+ def initialize(message:, input_name: nil)
10
+ @message = message
11
+ @input_name = input_name&.to_sym
12
+
13
+ super(message)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Exceptions
5
+ class Internal < Base
6
+ attr_reader :message,
7
+ :internal_name
8
+
9
+ def initialize(message:, internal_name: nil)
10
+ @message = message
11
+ @internal_name = internal_name&.to_sym
12
+
13
+ super(message)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Exceptions
5
+ class Output < Base
6
+ attr_reader :message,
7
+ :output_name
8
+
9
+ def initialize(message:, output_name: nil)
10
+ @message = message
11
+ @output_name = output_name&.to_sym
12
+
13
+ super(message)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -35,7 +35,7 @@ module Servactory
35
35
  conflict_code: input.conflict_code
36
36
  )
37
37
 
38
- raise @context.class.config.input_error_class.new(
38
+ raise @context.class.config.input_exception_class.new(
39
39
  message: message_text,
40
40
  input_name: input.name
41
41
  )
@@ -23,7 +23,7 @@ module Servactory
23
23
  unnecessary_attributes: unnecessary_attributes.join(", ")
24
24
  )
25
25
 
26
- raise @context.class.config.input_error_class.new(message: message_text)
26
+ raise @context.class.config.input_exception_class.new(message: message_text)
27
27
  end
28
28
 
29
29
  private
@@ -73,7 +73,7 @@ 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_error_class.new(message: tmp_errors.first)
76
+ raise @context.class.config.input_exception_class.new(message: tmp_errors.first)
77
77
  end
78
78
  end
79
79
  end
@@ -71,7 +71,7 @@ module Servactory
71
71
  return if (tmp_errors = errors.not_blank).empty?
72
72
 
73
73
  raise @context.class.config
74
- .public_send(:"#{@attribute.system_name}_error_class")
74
+ .public_send(:"#{@attribute.system_name}_exception_class")
75
75
  .new(message: tmp_errors.first)
76
76
  end
77
77
  end
@@ -3,8 +3,8 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 2
7
- PATCH = 3
6
+ MINOR = 3
7
+ PATCH = 1
8
8
  PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
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.2.3
4
+ version: 2.3.1
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-03-05 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -265,6 +265,10 @@ files:
265
265
  - lib/servactory/errors/internal_error.rb
266
266
  - lib/servactory/errors/output_error.rb
267
267
  - lib/servactory/exceptions/base.rb
268
+ - lib/servactory/exceptions/failure.rb
269
+ - lib/servactory/exceptions/input.rb
270
+ - lib/servactory/exceptions/internal.rb
271
+ - lib/servactory/exceptions/output.rb
268
272
  - lib/servactory/exceptions/success.rb
269
273
  - lib/servactory/info/dsl.rb
270
274
  - lib/servactory/info/result.rb