servactory 1.6.3 → 1.6.5

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: 321c1d5afff2d05fca47c222254ed759bcab36acce61f346d4a141f936e25fa7
4
- data.tar.gz: 9820d66f4f2985665b3552583c2f84eddeb6860cb588c5444da7f32d32bf6c89
3
+ metadata.gz: 7e0ef0253d0030321767ea6a532f52fada7923dcf9f0cc87e7651d7df5a1ec57
4
+ data.tar.gz: 5e080cef06176ffdd734802503cf987fa6608f3acccf7d1497da6ad0968142c9
5
5
  SHA512:
6
- metadata.gz: 3db3d15d89132bcb65afe6d25f278cb59e3c40f1cae70a02bb9f8af681356dc2aa14e05017c03088a10baf6b1de22833aaa3b70fb6f3138027cb283a279b77cb
7
- data.tar.gz: 1d01c55aba13762649115010a8cb3ca99489773abc8d48236529139318f9f12e636de08b8b66c417157918ff44b7223d0d9bd9a0f9faa9663aef1e908a869d79
6
+ metadata.gz: 1195d6f2dcebe355307197eaf11cf0591ba5d9486020572afc8e4991741920664d0f8525052c1d1742e9af14eee627634e7be439529e9827ecfdaa437e87c8a0
7
+ data.tar.gz: 48ed814dff14b30ac71d3484649ac7412e54ec8edcdc2bc8bcaa925d2babac1573efd473547717d83ea821064926ca8a9810c34fa91995d018d7b5e6c23bc221
data/README.md CHANGED
@@ -11,7 +11,7 @@ See [servactory.com](https://servactory.com) for documentation.
11
11
 
12
12
  ## Contributing
13
13
 
14
- This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. We recommend reading the [contributing guide](./docs/pages/CONTRIBUTING.md) as well.
14
+ This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. We recommend reading the [contributing guide](./website/docs/CONTRIBUTING.md) as well.
15
15
 
16
16
  ## License
17
17
 
@@ -11,13 +11,45 @@ module Servactory
11
11
  def inherited(child)
12
12
  super
13
13
 
14
- child.send(:collection_of_methods).merge(collection_of_methods)
14
+ child.send(:collection_of_stages).merge(collection_of_stages)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
- def make(name, **options)
20
- collection_of_methods << Method.new(name, **options)
19
+ def stage(&block)
20
+ @current_stage = Stage.new(position: next_position)
21
+
22
+ instance_eval(&block)
23
+
24
+ @current_stage = nil
25
+
26
+ nil
27
+ end
28
+
29
+ def wrap_in(wrapper)
30
+ return if @current_stage.blank?
31
+
32
+ @current_stage.wrapper = wrapper
33
+ end
34
+
35
+ def rollback(rollback)
36
+ return if @current_stage.blank?
37
+
38
+ @current_stage.rollback = rollback
39
+ end
40
+
41
+ def make(name, position: nil, **options)
42
+ position = position.presence || next_position
43
+
44
+ @current_stage = @current_stage.presence || Stage.new(position: position)
45
+
46
+ @current_stage.methods << Method.new(
47
+ name,
48
+ position: position,
49
+ **options
50
+ )
51
+
52
+ collection_of_stages << @current_stage
21
53
  end
22
54
 
23
55
  def method_missing(shortcut_name, *args, &block)
@@ -34,12 +66,16 @@ module Servactory
34
66
  Servactory.configuration.method_shortcuts.include?(shortcut_name) || super
35
67
  end
36
68
 
37
- def collection_of_methods
38
- @collection_of_methods ||= Collection.new
69
+ def next_position
70
+ collection_of_stages.size + 1
71
+ end
72
+
73
+ def collection_of_stages
74
+ @collection_of_stages ||= StageCollection.new
39
75
  end
40
76
 
41
77
  def methods_workbench
42
- @methods_workbench ||= Workbench.work_with(collection_of_methods)
78
+ @methods_workbench ||= Workbench.work_with(collection_of_stages)
43
79
  end
44
80
  end
45
81
  end
@@ -4,11 +4,13 @@ module Servactory
4
4
  module Methods
5
5
  class Method
6
6
  attr_reader :name,
7
+ :position,
7
8
  :condition,
8
9
  :is_condition_opposite
9
10
 
10
- def initialize(name, **options)
11
+ def initialize(name, position:, **options)
11
12
  @name = name
13
+ @position = position
12
14
 
13
15
  @is_condition_opposite = false
14
16
  @condition = options.fetch(:if, nil)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Methods
5
+ class MethodCollection
6
+ # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
+ extend Forwardable
8
+ def_delegators :@collection, :<<, :each, :sort_by
9
+
10
+ def initialize(collection = Set.new)
11
+ @collection = collection
12
+ end
13
+
14
+ def sorted_by_position
15
+ MethodCollection.new(sort_by(&:position))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Methods
5
+ class Stage
6
+ attr_accessor :position,
7
+ :wrapper,
8
+ :rollback
9
+
10
+ def initialize(position:, wrapper: nil, rollback: nil)
11
+ @position = position
12
+ @wrapper = wrapper
13
+ @rollback = rollback
14
+ end
15
+
16
+ def next_method_position
17
+ methods.size + 1
18
+ end
19
+
20
+ def methods
21
+ @methods ||= MethodCollection.new
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Servactory
4
+ module Methods
5
+ class StageCollection
6
+ # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
+ extend Forwardable
8
+ def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
9
+
10
+ def initialize(collection = Set.new)
11
+ @collection = collection
12
+ end
13
+
14
+ def sorted_by_position
15
+ StageCollection.new(sort_by(&:position))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,8 +7,8 @@ module Servactory
7
7
  new(...)
8
8
  end
9
9
 
10
- def initialize(collection_of_methods)
11
- @collection_of_methods = collection_of_methods
10
+ def initialize(collection_of_stages)
11
+ @collection_of_stages = collection_of_stages
12
12
  end
13
13
 
14
14
  def assign(context:)
@@ -16,24 +16,48 @@ module Servactory
16
16
  end
17
17
 
18
18
  def run!
19
- return try_to_use_call if collection_of_methods.empty?
19
+ return try_to_use_call if collection_of_stages.empty?
20
20
 
21
- collection_of_methods.each do |make_method|
22
- next if unnecessary_for?(make_method)
23
-
24
- context.send(make_method.name)
21
+ collection_of_stages.sorted_by_position.each do |stage|
22
+ call_stage(stage)
25
23
  end
26
24
  end
27
25
 
28
26
  private
29
27
 
30
28
  attr_reader :context,
31
- :collection_of_methods
29
+ :collection_of_stages
32
30
 
33
31
  def try_to_use_call
34
32
  context.try(:send, :call)
35
33
  end
36
34
 
35
+ def call_stage(stage)
36
+ wrapper = stage.wrapper
37
+ rollback = stage.rollback
38
+ methods = stage.methods.sorted_by_position
39
+
40
+ if wrapper.is_a?(Proc)
41
+ call_wrapper_with_methods(wrapper, rollback, methods)
42
+ else
43
+ call_methods(methods)
44
+ end
45
+ end
46
+
47
+ def call_wrapper_with_methods(wrapper, rollback, methods)
48
+ wrapper.call(methods: -> { call_methods(methods) })
49
+ rescue StandardError => e
50
+ context.send(rollback, e) if rollback.present?
51
+ end
52
+
53
+ def call_methods(methods)
54
+ methods.each do |make_method|
55
+ next if unnecessary_for?(make_method)
56
+
57
+ context.send(make_method.name)
58
+ end
59
+ end
60
+
37
61
  def unnecessary_for?(make_method)
38
62
  condition = make_method.condition
39
63
  is_condition_opposite = make_method.is_condition_opposite
@@ -4,7 +4,7 @@ module Servactory
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 6
7
- PATCH = 3
7
+ PATCH = 5
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  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: 1.6.3
4
+ version: 1.6.5
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-05-30 00:00:00.000000000 Z
11
+ date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -231,10 +231,12 @@ files:
231
231
  - lib/servactory/internals/validations/base.rb
232
232
  - lib/servactory/internals/validations/type.rb
233
233
  - lib/servactory/internals/workbench.rb
234
- - lib/servactory/methods/collection.rb
235
234
  - lib/servactory/methods/dsl.rb
236
235
  - lib/servactory/methods/method.rb
236
+ - lib/servactory/methods/method_collection.rb
237
237
  - lib/servactory/methods/shortcuts/collection.rb
238
+ - lib/servactory/methods/stage.rb
239
+ - lib/servactory/methods/stage_collection.rb
238
240
  - lib/servactory/methods/workbench.rb
239
241
  - lib/servactory/outputs/collection.rb
240
242
  - lib/servactory/outputs/dsl.rb
@@ -252,7 +254,9 @@ licenses:
252
254
  - MIT
253
255
  metadata:
254
256
  homepage_uri: https://github.com/afuno/servactory
257
+ documentation_uri: https://servactory.com
255
258
  source_code_uri: https://github.com/afuno/servactory
259
+ bug_tracker_uri: https://github.com/afuno/servactory/issues
256
260
  changelog_uri: https://github.com/afuno/servactory/blob/master/CHANGELOG.md
257
261
  rubygems_mfa_required: 'true'
258
262
  post_install_message:
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Servactory
4
- module Methods
5
- class Collection
6
- # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
- extend Forwardable
8
- def_delegators :@collection, :<<, :each, :merge, :empty?
9
-
10
- def initialize(*)
11
- @collection = Set.new
12
- end
13
- end
14
- end
15
- end