servactory 2.7.0 → 2.9.0.rc1

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: f0392bf65a7bdc8c133d517c581655e2a29ce4665d8a2c9dcde7eec7e1a6d1cc
4
- data.tar.gz: 5f57c9201660ae628fb471f1bef146acb2face2aad22f10b02a0a1e2b1f9fd55
3
+ metadata.gz: ca75399cdb14c4dc3b28703e9c3b2baf353f0612d8414de865f780a69dc56e74
4
+ data.tar.gz: 74c08748d40a6233942c5c4b0b34f7b0ccb0a63776468d98ea08fda660b826fd
5
5
  SHA512:
6
- metadata.gz: f6741ccebe3ddb1f8a7b6c2908a92b5b6a3f4af00d188c5e1d2f54f663d5758ebc3956c5a0ca2efa97fed0fe97187e594557083a0cd6ca2372487430c6ca005e
7
- data.tar.gz: e2374b66d0d8b6b3c49b07f66bc7532034957ff3985e4a776686f6c90329e2d30ed7b5f85834f12ef272a204c484689b8b6480a933256b8ec64fb274a69d58e4
6
+ metadata.gz: f48fd065703fde42c80f14dae2045ea1af0c31d66c5eece2ccd4cb94358c089d7ca4e59417588a6f40dbd77376786377ad4ef90285f4d6a545925d5ecc0f0f8e
7
+ data.tar.gz: c495107855b7a1939717457638e7171ef1deb9f979426dbdc5084c84ecc78b87bc38688a71df458a9afc5ee5befe7141c78122f7f071af00c5120ef15a0480a7
@@ -2,41 +2,11 @@
2
2
 
3
3
  module Servactory
4
4
  module Configuration
5
- class Factory # rubocop:disable Metrics/ClassLength
5
+ class Factory
6
6
  def initialize(config)
7
7
  @config = config
8
8
  end
9
9
 
10
- # DEPRECATED: These configs must be deleted after release 2.4.
11
- def 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)
28
- end
29
-
30
- # DEPRECATED: These configs must be deleted after release 2.4.
31
- def 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)
38
- end
39
-
40
10
  def input_exception_class(input_exception_class)
41
11
  return @config.input_exception_class = input_exception_class if subclass_of_exception?(input_exception_class)
42
12
 
@@ -6,7 +6,7 @@ module Servactory
6
6
  def call!(arguments = {})
7
7
  context = send(:new)
8
8
 
9
- _call!(context, **arguments)
9
+ _call!(context, arguments)
10
10
 
11
11
  config.result_class.success_for(context:)
12
12
  rescue config.success_class => e
@@ -16,7 +16,7 @@ module Servactory
16
16
  def call(arguments = {})
17
17
  context = send(:new)
18
18
 
19
- _call!(context, **arguments)
19
+ _call!(context, arguments)
20
20
 
21
21
  config.result_class.success_for(context:)
22
22
  rescue config.success_class => e
@@ -27,10 +27,12 @@ module Servactory
27
27
 
28
28
  private
29
29
 
30
- def _call!(context, **arguments)
30
+ def _call!(context, incoming_arguments)
31
+ incoming_arguments = Servactory::Utils.adapt(incoming_arguments)
32
+
31
33
  context.send(
32
34
  :_call!,
33
- incoming_arguments: arguments.symbolize_keys,
35
+ incoming_arguments:,
34
36
  collection_of_inputs:,
35
37
  collection_of_internals:,
36
38
  collection_of_outputs:,
@@ -27,6 +27,9 @@ module Servactory
27
27
 
28
28
  ############################################################################
29
29
 
30
+ STATE_PREDICATE_NAMES = %i[success? failure?].freeze
31
+ private_constant :STATE_PREDICATE_NAMES
32
+
30
33
  def self.success_for(context:)
31
34
  new(context:).send(:as_success)
32
35
  end
@@ -40,6 +43,14 @@ module Servactory
40
43
  @exception = exception
41
44
  end
42
45
 
46
+ def to_h
47
+ filtered = methods(false).filter do |key|
48
+ !key.in?(STATE_PREDICATE_NAMES) && !key.to_s.end_with?("?")
49
+ end
50
+
51
+ filtered.to_h { |key| [key, public_send(key)] }.compact
52
+ end
53
+
43
54
  def inspect
44
55
  "#<#{self.class.name} #{draw_result}>"
45
56
  end
@@ -13,7 +13,7 @@ module Servactory
13
13
  @attribute_type = attribute_type
14
14
  @attribute_type_plural = attribute_type.to_s.pluralize.to_sym
15
15
  @attribute_name = attribute_name
16
- @attributes = attributes
16
+ @attributes = attributes.is_a?(FalseClass) ? attributes : Servactory::Utils.adapt(attributes)
17
17
 
18
18
  @attribute_data = described_class.info.public_send(attribute_type_plural).fetch(attribute_name)
19
19
 
@@ -2,7 +2,15 @@
2
2
 
3
3
  module Servactory
4
4
  module Utils
5
- module_function
5
+ extend self
6
+
7
+ def adapt(data)
8
+ if defined?(Datory::Base) && data.is_a?(Datory::Base)
9
+ data = Servactory::Utils.send(:instance_variables_to_hash_from, data)
10
+ end
11
+
12
+ data.symbolize_keys
13
+ end
6
14
 
7
15
  def fetch_hash_with_desired_attribute(attribute)
8
16
  return { input: attribute.class::Actor.new(attribute) } if really_input?(attribute)
@@ -97,5 +105,24 @@ module Servactory
97
105
  class_or_name
98
106
  end
99
107
  end
108
+
109
+ private
110
+
111
+ def instance_variables_to_hash_from(data) # rubocop:disable Metrics/MethodLength
112
+ data.instance_variables.to_h do |key|
113
+ value = data.instance_variable_get(key)
114
+
115
+ value =
116
+ if value.is_a?(Set) || value.is_a?(Array)
117
+ value.map { |item| instance_variables_to_hash_from(item) }
118
+ elsif value.is_a?(Datory::Base)
119
+ instance_variables_to_hash_from(value)
120
+ else
121
+ value
122
+ end
123
+
124
+ [key.to_s.delete_prefix("@"), value]
125
+ end
126
+ end
100
127
  end
101
128
  end
@@ -3,9 +3,9 @@
3
3
  module Servactory
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 7
6
+ MINOR = 9
7
7
  PATCH = 0
8
- PRE = nil
8
+ PRE = "rc1"
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.7.0
4
+ version: 2.9.0.rc1
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-08-13 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '1.31'
89
+ - !ruby/object:Gem::Dependency
90
+ name: datory
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.1.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.1.0
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: pry
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -271,10 +285,6 @@ files:
271
285
  - lib/servactory/context/workspace/outputs.rb
272
286
  - lib/servactory/dsl.rb
273
287
  - lib/servactory/engine.rb
274
- - lib/servactory/errors/failure.rb
275
- - lib/servactory/errors/input_error.rb
276
- - lib/servactory/errors/internal_error.rb
277
- - lib/servactory/errors/output_error.rb
278
288
  - lib/servactory/exceptions/base.rb
279
289
  - lib/servactory/exceptions/failure.rb
280
290
  - lib/servactory/exceptions/input.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Errors
5
- # DEPRECATED: This class will be deleted after release 2.4.
6
- class Failure < Servactory::Exceptions::Base
7
- attr_reader :type,
8
- :message,
9
- :meta
10
-
11
- def initialize(type: :base, message:, meta: nil) # rubocop:disable Style/KeywordParametersOrder
12
- @type = type
13
- @message = message
14
- @meta = meta
15
-
16
- super(message)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Errors
5
- # DEPRECATED: This class will be deleted after release 2.4.
6
- class InputError < Servactory::Exceptions::Base
7
- attr_reader :message,
8
- :input_name,
9
- :meta
10
-
11
- def initialize(message:, input_name: nil, meta: nil)
12
- @message = message
13
- @input_name = input_name&.to_sym
14
- @meta = meta
15
-
16
- super(message)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Errors
5
- # DEPRECATED: This class will be deleted after release 2.4.
6
- class InternalError < Servactory::Exceptions::Base
7
- attr_reader :message,
8
- :internal_name,
9
- :meta
10
-
11
- def initialize(message:, internal_name: nil, meta: nil)
12
- @message = message
13
- @internal_name = internal_name&.to_sym
14
- @meta = meta
15
-
16
- super(message)
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Errors
5
- # DEPRECATED: This class will be deleted after release 2.4.
6
- class OutputError < Servactory::Exceptions::Base
7
- attr_reader :message,
8
- :output_name,
9
- :meta
10
-
11
- def initialize(message:, output_name: nil, meta: nil)
12
- @message = message
13
- @output_name = output_name&.to_sym
14
- @meta = meta
15
-
16
- super(message)
17
- end
18
- end
19
- end
20
- end