servactory 1.7.1 → 1.8.1
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 +4 -4
- data/README.md +13 -5
- data/lib/servactory/configuration/factory.rb +6 -2
- data/lib/servactory/configuration/setup.rb +4 -2
- data/lib/servactory/context/callable.rb +4 -8
- data/lib/servactory/context/workspace.rb +2 -30
- data/lib/servactory/inputs/input.rb +11 -5
- data/lib/servactory/inputs/options_collection.rb +9 -1
- data/lib/servactory/methods/aliases_for_make/collection.rb +17 -0
- data/lib/servactory/methods/dsl.rb +24 -3
- data/lib/servactory/methods/{shortcuts → shortcuts_for_make}/collection.rb +1 -1
- data/lib/servactory/result.rb +45 -15
- data/lib/servactory/version.rb +1 -1
- metadata +4 -4
- data/lib/servactory/errors/collection.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4b777f0ef9ef743ab9af34ced8c2170a96585ecbb4fc6fdb290c07afc05ebf
|
4
|
+
data.tar.gz: 01e57d03342d0aa21bd4d49782dcbf9107ae94be2f2761511845313023bf6865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af1bd571ef3ad8941778c32fde6cd76eafcc8afc01f2966a2517b05d2dfcd51cdd108b6c0168af019e56094d98eaa3d75a530c85874eedcb6aeeb5aacda7e823
|
7
|
+
data.tar.gz: cafe7ad733b25bf2bf1e27ee8809a6f659c127fbd4bdb0ae9bffdb9240e9d2671b6217867442834351461f0a6ace6435a4bc9d42bd2b0e0ad31ff93d4bf232c1
|
data/README.md
CHANGED
@@ -9,12 +9,18 @@ A set of tools for building reliable services of any complexity.
|
|
9
9
|
|
10
10
|
See [servactory.com](https://servactory.com) for documentation.
|
11
11
|
|
12
|
-
##
|
12
|
+
## Example
|
13
|
+
|
14
|
+
### Installation
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "servactory"
|
18
|
+
```
|
13
19
|
|
14
20
|
### Service
|
15
21
|
|
16
22
|
```ruby
|
17
|
-
class UserService::Authenticate <
|
23
|
+
class UserService::Authenticate < Servactory::Base
|
18
24
|
input :email, type: String
|
19
25
|
input :password, type: String
|
20
26
|
|
@@ -32,7 +38,7 @@ class UserService::Authenticate < ApplicationService::Base
|
|
32
38
|
end
|
33
39
|
```
|
34
40
|
|
35
|
-
###
|
41
|
+
### Usage
|
36
42
|
|
37
43
|
```ruby
|
38
44
|
class SessionsController < ApplicationController
|
@@ -58,8 +64,10 @@ end
|
|
58
64
|
|
59
65
|
## Contributing
|
60
66
|
|
61
|
-
This project is intended to be a safe, welcoming space for collaboration.
|
67
|
+
This project is intended to be a safe, welcoming space for collaboration.
|
68
|
+
Contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
69
|
+
We recommend reading the [contributing guide](./website/docs/CONTRIBUTING.md) as well.
|
62
70
|
|
63
71
|
## License
|
64
72
|
|
65
|
-
|
73
|
+
Servactory is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -23,8 +23,12 @@ module Servactory
|
|
23
23
|
Servactory.configuration.input_option_helpers.merge(input_option_helpers)
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
Servactory.configuration.
|
26
|
+
def aliases_for_make(aliases_for_make)
|
27
|
+
Servactory.configuration.aliases_for_make.merge(aliases_for_make)
|
28
|
+
end
|
29
|
+
|
30
|
+
def shortcuts_for_make(shortcuts_for_make)
|
31
|
+
Servactory.configuration.shortcuts_for_make.merge(shortcuts_for_make)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
@@ -8,7 +8,8 @@ module Servactory
|
|
8
8
|
:output_error_class,
|
9
9
|
:failure_class,
|
10
10
|
:input_option_helpers,
|
11
|
-
:
|
11
|
+
:aliases_for_make,
|
12
|
+
:shortcuts_for_make
|
12
13
|
|
13
14
|
def initialize
|
14
15
|
@input_error_class = Servactory::Errors::InputError
|
@@ -19,7 +20,8 @@ module Servactory
|
|
19
20
|
|
20
21
|
@input_option_helpers = Servactory::Inputs::OptionHelpersCollection.new(default_input_option_helpers)
|
21
22
|
|
22
|
-
@
|
23
|
+
@aliases_for_make = Servactory::Methods::AliasesForMake::Collection.new
|
24
|
+
@shortcuts_for_make = Servactory::Methods::ShortcutsForMake::Collection.new
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
@@ -6,8 +6,6 @@ module Servactory
|
|
6
6
|
def call!(arguments = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
7
7
|
@context_store = Store.new(self)
|
8
8
|
|
9
|
-
context_store.context.send(:assign_service_strict_mode, true)
|
10
|
-
|
11
9
|
assign_data_with(arguments)
|
12
10
|
|
13
11
|
inputs_workbench.find_unnecessary!
|
@@ -20,9 +18,7 @@ module Servactory
|
|
20
18
|
|
21
19
|
methods_workbench.run!
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
Servactory::Result.prepare_for(
|
21
|
+
Servactory::Result.success_for(
|
26
22
|
context: context_store.context,
|
27
23
|
collection_of_outputs: collection_of_outputs
|
28
24
|
)
|
@@ -31,8 +27,6 @@ module Servactory
|
|
31
27
|
def call(arguments = {}) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
32
28
|
@context_store = Store.new(self)
|
33
29
|
|
34
|
-
context_store.context.send(:assign_service_strict_mode, false)
|
35
|
-
|
36
30
|
assign_data_with(arguments)
|
37
31
|
|
38
32
|
inputs_workbench.find_unnecessary!
|
@@ -45,10 +39,12 @@ module Servactory
|
|
45
39
|
|
46
40
|
methods_workbench.run!
|
47
41
|
|
48
|
-
Servactory::Result.
|
42
|
+
Servactory::Result.success_for(
|
49
43
|
context: context_store.context,
|
50
44
|
collection_of_outputs: collection_of_outputs
|
51
45
|
)
|
46
|
+
rescue Servactory.configuration.failure_class => e
|
47
|
+
Servactory::Result.failure_for(exception: e)
|
52
48
|
end
|
53
49
|
|
54
50
|
private
|
@@ -18,20 +18,6 @@ module Servactory
|
|
18
18
|
end
|
19
19
|
alias out outputs
|
20
20
|
|
21
|
-
def errors
|
22
|
-
@errors ||= Servactory::Errors::Collection.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def error
|
26
|
-
errors.first
|
27
|
-
end
|
28
|
-
|
29
|
-
def raise_first_fail
|
30
|
-
return if (tmp_errors = errors.for_fails.not_blank).empty?
|
31
|
-
|
32
|
-
raise tmp_errors.first
|
33
|
-
end
|
34
|
-
|
35
21
|
protected
|
36
22
|
|
37
23
|
def fail_input!(input_name, message:)
|
@@ -41,22 +27,8 @@ module Servactory
|
|
41
27
|
)
|
42
28
|
end
|
43
29
|
|
44
|
-
def fail!(
|
45
|
-
message
|
46
|
-
failure_class: Servactory.configuration.failure_class,
|
47
|
-
meta: nil
|
48
|
-
)
|
49
|
-
failure = failure_class.new(message: message, meta: meta)
|
50
|
-
|
51
|
-
raise failure if @service_strict_mode
|
52
|
-
|
53
|
-
errors << failure
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def assign_service_strict_mode(flag)
|
59
|
-
@service_strict_mode = flag
|
30
|
+
def fail!(message:, meta: nil)
|
31
|
+
raise Servactory.configuration.failure_class.new(message: message, meta: meta)
|
60
32
|
end
|
61
33
|
end
|
62
34
|
end
|
@@ -24,14 +24,20 @@ module Servactory
|
|
24
24
|
options = apply_helpers_for_options(helpers: helpers, options: options) if helpers.present?
|
25
25
|
|
26
26
|
add_basic_options_with(type: type, options: options)
|
27
|
+
end
|
28
|
+
# rubocop:enable Style/KeywordParametersOrder
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
def method_missing(name, *args, &block)
|
31
|
+
option = collection_of_options.find_by(name: name)
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
return super if option.nil?
|
34
|
+
|
35
|
+
option.value
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_to_missing?(name, *)
|
39
|
+
collection_of_options.names.include?(name) || super
|
33
40
|
end
|
34
|
-
# rubocop:enable Style/KeywordParametersOrder
|
35
41
|
|
36
42
|
def apply_helpers_for_options(helpers:, options:)
|
37
43
|
prepared_options = {}
|
@@ -5,12 +5,16 @@ module Servactory
|
|
5
5
|
class OptionsCollection
|
6
6
|
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :@collection, :<<, :filter, :each, :map, :flat_map
|
8
|
+
def_delegators :@collection, :<<, :filter, :each, :map, :flat_map, :find
|
9
9
|
|
10
10
|
def initialize(*)
|
11
11
|
@collection = Set.new
|
12
12
|
end
|
13
13
|
|
14
|
+
def names
|
15
|
+
map(&:name)
|
16
|
+
end
|
17
|
+
|
14
18
|
def validation_classes
|
15
19
|
filter { |option| option.validation_class.present? }.map(&:validation_class).uniq
|
16
20
|
end
|
@@ -34,6 +38,10 @@ module Servactory
|
|
34
38
|
end
|
35
39
|
end.reject(&:blank?).first
|
36
40
|
end
|
41
|
+
|
42
|
+
def find_by(name:)
|
43
|
+
find { |option| option.name == name }
|
44
|
+
end
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Servactory
|
4
|
+
module Methods
|
5
|
+
module AliasesForMake
|
6
|
+
class Collection
|
7
|
+
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@collection, :<<, :merge, :include?
|
10
|
+
|
11
|
+
def initialize(*)
|
12
|
+
@collection = Set.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -58,9 +58,28 @@ module Servactory
|
|
58
58
|
collection_of_stages << @current_stage
|
59
59
|
end
|
60
60
|
|
61
|
-
def method_missing(
|
62
|
-
|
61
|
+
def method_missing(name, *args, &block)
|
62
|
+
if Servactory.configuration.aliases_for_make.include?(name)
|
63
|
+
return method_missing_for_aliases_for_make(name, *args, &block)
|
64
|
+
end
|
65
|
+
|
66
|
+
if Servactory.configuration.shortcuts_for_make.include?(name)
|
67
|
+
return method_missing_for_shortcuts_for_make(name, *args, &block)
|
68
|
+
end
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
73
|
+
def method_missing_for_aliases_for_make(_alias_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
|
74
|
+
method_name = args.first
|
75
|
+
method_options = args.last.is_a?(Hash) ? args.pop : {}
|
76
|
+
|
77
|
+
return if method_name.nil?
|
78
|
+
|
79
|
+
make(method_name, **method_options)
|
80
|
+
end
|
63
81
|
|
82
|
+
def method_missing_for_shortcuts_for_make(shortcut_name, *args, &block) # rubocop:disable Lint/UnusedMethodArgument
|
64
83
|
method_options = args.last.is_a?(Hash) ? args.pop : {}
|
65
84
|
|
66
85
|
args.each do |method_name|
|
@@ -69,7 +88,9 @@ module Servactory
|
|
69
88
|
end
|
70
89
|
|
71
90
|
def respond_to_missing?(shortcut_name, *)
|
72
|
-
Servactory.configuration.
|
91
|
+
Servactory.configuration.aliases_for_make.include?(shortcut_name) ||
|
92
|
+
Servactory.configuration.shortcuts_for_make.include?(name) ||
|
93
|
+
super
|
73
94
|
end
|
74
95
|
|
75
96
|
def next_position
|
data/lib/servactory/result.rb
CHANGED
@@ -2,32 +2,62 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
class Result
|
5
|
-
def self.
|
6
|
-
new.send(:
|
5
|
+
def self.success_for(...)
|
6
|
+
new(...).send(:as_success)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.failure_for(...)
|
10
|
+
new(...).send(:as_failure)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(context: nil, collection_of_outputs: nil, exception: nil)
|
14
|
+
@context = context
|
15
|
+
@collection_of_outputs = collection_of_outputs
|
16
|
+
@exception = exception
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(name, *args, &block)
|
20
|
+
output = @collection_of_outputs&.find_by(name: name)
|
21
|
+
|
22
|
+
return super if output.nil?
|
23
|
+
|
24
|
+
output_value_for(output)
|
25
|
+
end
|
26
|
+
|
27
|
+
def respond_to_missing?(name, *)
|
28
|
+
@collection_of_outputs&.names&.include?(name) || super
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class.name} #{draw_result}>"
|
7
33
|
end
|
8
34
|
|
9
35
|
private
|
10
36
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
37
|
+
def as_success
|
38
|
+
define_singleton_method(:success?) { true }
|
39
|
+
define_singleton_method(:failure?) { false }
|
14
40
|
|
15
41
|
self
|
16
42
|
end
|
17
43
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
44
|
+
def as_failure
|
45
|
+
define_singleton_method(:error) { @exception }
|
46
|
+
|
47
|
+
define_singleton_method(:success?) { false }
|
48
|
+
define_singleton_method(:failure?) { true }
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
21
52
|
|
22
|
-
|
23
|
-
|
53
|
+
def draw_result
|
54
|
+
@collection_of_outputs&.map do |output|
|
55
|
+
"@#{output.name}=#{output_value_for(output).inspect}"
|
56
|
+
end&.join(", ")
|
24
57
|
end
|
25
58
|
|
26
|
-
def
|
27
|
-
|
28
|
-
define_singleton_method(:error) { context.error }
|
29
|
-
define_singleton_method(:success?) { context.errors.empty? }
|
30
|
-
define_singleton_method(:failure?) { !context.errors.empty? }
|
59
|
+
def output_value_for(output)
|
60
|
+
@context.instance_variable_get(:"@#{output.name}")
|
31
61
|
end
|
32
62
|
end
|
33
63
|
end
|
data/lib/servactory/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.8.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: 2023-06-
|
11
|
+
date: 2023-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -202,7 +202,6 @@ files:
|
|
202
202
|
- lib/servactory/context/workspace/outputs.rb
|
203
203
|
- lib/servactory/engine.rb
|
204
204
|
- lib/servactory/errors/base.rb
|
205
|
-
- lib/servactory/errors/collection.rb
|
206
205
|
- lib/servactory/errors/failure.rb
|
207
206
|
- lib/servactory/errors/input_error.rb
|
208
207
|
- lib/servactory/errors/internal_error.rb
|
@@ -235,10 +234,11 @@ files:
|
|
235
234
|
- lib/servactory/internals/validations/base.rb
|
236
235
|
- lib/servactory/internals/validations/type.rb
|
237
236
|
- lib/servactory/internals/workbench.rb
|
237
|
+
- lib/servactory/methods/aliases_for_make/collection.rb
|
238
238
|
- lib/servactory/methods/dsl.rb
|
239
239
|
- lib/servactory/methods/method.rb
|
240
240
|
- lib/servactory/methods/method_collection.rb
|
241
|
-
- lib/servactory/methods/
|
241
|
+
- lib/servactory/methods/shortcuts_for_make/collection.rb
|
242
242
|
- lib/servactory/methods/stage.rb
|
243
243
|
- lib/servactory/methods/stage_collection.rb
|
244
244
|
- lib/servactory/methods/workbench.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Servactory
|
4
|
-
module Errors
|
5
|
-
class Collection
|
6
|
-
# NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
|
7
|
-
extend Forwardable
|
8
|
-
def_delegators :@collection, :<<, :to_a, :filter, :reject, :empty?, :first
|
9
|
-
|
10
|
-
def initialize(collection = Set.new)
|
11
|
-
@collection = collection
|
12
|
-
end
|
13
|
-
|
14
|
-
def not_blank
|
15
|
-
Collection.new(reject(&:blank?))
|
16
|
-
end
|
17
|
-
|
18
|
-
def for_fails
|
19
|
-
filtered = filter { |error| error.is_a?(Failure) }
|
20
|
-
|
21
|
-
Collection.new(filtered)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|