servactory 1.6.4 → 1.6.5

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: e8baf1ff3aab8a43c92e83987cb5f4cfbc426be9aacabf5fe63dd01e133c891e
4
- data.tar.gz: 0af5e8fe8bf02fe5f15c68655e298b2d097b402764d231045683907afa35ded3
3
+ metadata.gz: 7e0ef0253d0030321767ea6a532f52fada7923dcf9f0cc87e7651d7df5a1ec57
4
+ data.tar.gz: 5e080cef06176ffdd734802503cf987fa6608f3acccf7d1497da6ad0968142c9
5
5
  SHA512:
6
- metadata.gz: aa8ffc01e6bab482d397f07e18847ec5d0b70bbd1e94bf7ff1ab6f080efca2502547ee92db3b663ba2bac15c2c6add762094ab37d9c47b73eb7b66f8f3ed9b10
7
- data.tar.gz: a15fc2c38e21b6637ff5b9f1273006c0aae2dfe5d8d084390a18e2ce262329510fe80ab2bc16d47f18f3da8a40c5f5daea0533ad4b611a0e9ce8868eacf87b8f
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,17 +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 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
+
19
41
  def make(name, position: nil, **options)
20
- collection_of_methods << Method.new(
42
+ position = position.presence || next_position
43
+
44
+ @current_stage = @current_stage.presence || Stage.new(position: position)
45
+
46
+ @current_stage.methods << Method.new(
21
47
  name,
22
- position: position.presence || next_position,
48
+ position: position,
23
49
  **options
24
50
  )
51
+
52
+ collection_of_stages << @current_stage
25
53
  end
26
54
 
27
55
  def method_missing(shortcut_name, *args, &block)
@@ -39,15 +67,15 @@ module Servactory
39
67
  end
40
68
 
41
69
  def next_position
42
- collection_of_methods.size + 1
70
+ collection_of_stages.size + 1
43
71
  end
44
72
 
45
- def collection_of_methods
46
- @collection_of_methods ||= Collection.new
73
+ def collection_of_stages
74
+ @collection_of_stages ||= StageCollection.new
47
75
  end
48
76
 
49
77
  def methods_workbench
50
- @methods_workbench ||= Workbench.work_with(collection_of_methods)
78
+ @methods_workbench ||= Workbench.work_with(collection_of_stages)
51
79
  end
52
80
  end
53
81
  end
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Servactory
4
4
  module Methods
5
- class Collection
5
+ class StageCollection
6
6
  # NOTE: http://words.steveklabnik.com/beware-subclassing-ruby-core-classes
7
7
  extend Forwardable
8
8
  def_delegators :@collection, :<<, :each, :merge, :sort_by, :size, :empty?
@@ -12,7 +12,7 @@ module Servactory
12
12
  end
13
13
 
14
14
  def sorted_by_position
15
- Collection.new(sort_by(&:position))
15
+ StageCollection.new(sort_by(&:position))
16
16
  end
17
17
  end
18
18
  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.sorted_by_position.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 = 4
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.4
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-06-03 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: