servactory 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- 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 -26
- 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 +19 -10
- 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: ddbffa6de1db943a943b369efceef704bb98c5160b13fcada0515069705af423
|
4
|
+
data.tar.gz: 4b6c33e2d95002a784468ee064ff83d90ce63e01f1ca323dc1afccad103c5063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57071853afa1e92822161608af16e9d303b03bdbe769110cb27d9e59be3d77b4517da5b55d8fdc93a86bcfd470617d5094d8ea03eeb5dd5abad342ead7ae1e9
|
7
|
+
data.tar.gz: ff862da58716ac985651f59d74aa49f44d06b10c6d8e000bc45877575f83062567f97e0acbaaa9559091ba888ec3a0dde38d9db571f400726a2c9a06a13d042e
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ class SessionsController < ApplicationController
|
|
43
43
|
session[:current_user_id] = service_result.user.id
|
44
44
|
redirect_to service_result.user
|
45
45
|
else
|
46
|
-
flash.now[:message] = service_result.
|
46
|
+
flash.now[:message] = service_result.error.message
|
47
47
|
render :new
|
48
48
|
end
|
49
49
|
end
|
@@ -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,16 +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 raise_first_fail
|
26
|
-
return if (tmp_errors = errors.for_fails.not_blank).empty?
|
27
|
-
|
28
|
-
raise tmp_errors.first
|
29
|
-
end
|
30
|
-
|
31
21
|
protected
|
32
22
|
|
33
23
|
def fail_input!(input_name, message:)
|
@@ -37,22 +27,8 @@ module Servactory
|
|
37
27
|
)
|
38
28
|
end
|
39
29
|
|
40
|
-
def fail!(
|
41
|
-
message
|
42
|
-
failure_class: Servactory.configuration.failure_class,
|
43
|
-
meta: nil
|
44
|
-
)
|
45
|
-
failure = failure_class.new(message: message, meta: meta)
|
46
|
-
|
47
|
-
raise failure if @service_strict_mode
|
48
|
-
|
49
|
-
errors << failure
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def assign_service_strict_mode(flag)
|
55
|
-
@service_strict_mode = flag
|
30
|
+
def fail!(message:, meta: nil)
|
31
|
+
raise Servactory.configuration.failure_class.new(message: message, meta: meta)
|
56
32
|
end
|
57
33
|
end
|
58
34
|
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,15 +2,30 @@
|
|
2
2
|
|
3
3
|
module Servactory
|
4
4
|
class Result
|
5
|
-
def self.
|
6
|
-
new.send(:
|
5
|
+
def self.success_for(...)
|
6
|
+
new.send(:success_for, ...)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.failure_for(...)
|
10
|
+
new.send(:failure_for, ...)
|
7
11
|
end
|
8
12
|
|
9
13
|
private
|
10
14
|
|
11
|
-
def
|
15
|
+
def success_for(context:, collection_of_outputs:)
|
12
16
|
prepare_outputs_with(context: context, collection_of_outputs: collection_of_outputs)
|
13
|
-
|
17
|
+
|
18
|
+
define_singleton_method(:success?) { true }
|
19
|
+
define_singleton_method(:failure?) { false }
|
20
|
+
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_for(exception:)
|
25
|
+
define_singleton_method(:error) { exception }
|
26
|
+
|
27
|
+
define_singleton_method(:success?) { false }
|
28
|
+
define_singleton_method(:failure?) { true }
|
14
29
|
|
15
30
|
self
|
16
31
|
end
|
@@ -22,11 +37,5 @@ module Servactory
|
|
22
37
|
instance_variable_set(:"@#{output.name}", context.instance_variable_get(:"@#{output.name}"))
|
23
38
|
end
|
24
39
|
end
|
25
|
-
|
26
|
-
def prepare_statuses_with(context:)
|
27
|
-
define_singleton_method(:errors) { context.errors }
|
28
|
-
define_singleton_method(:success?) { context.errors.empty? }
|
29
|
-
define_singleton_method(:failure?) { !context.errors.empty? }
|
30
|
-
end
|
31
40
|
end
|
32
41
|
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.0
|
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-20 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
|