steppy 1.0.2 → 1.0.3

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: b004c99544ed8e124ccdf1e699a421a0a70c1515ef2c095f26c2d50b0f76b97a
4
- data.tar.gz: 40ff04003443747d336ff6cab8771849ceff5f97282160e4581674d75ea0baf6
3
+ metadata.gz: 06bbbf8061978cb442a6dbd96a98c07bf4c856866674b7bd8719b76f3593ccef
4
+ data.tar.gz: 64c95196b0f8217622cf027d25b036987dbf0f82b86da162f94043bf36235aeb
5
5
  SHA512:
6
- metadata.gz: 5d8cda58c821abafe498dedb044e849c5cfb4e25a2e4d81e9113dee0c2bdb9927533421ac2046e32af84bc0f4092559d9b3996d6254f76f7afca78162fc71a9b
7
- data.tar.gz: 42c3c4587b6aa2fba5848a0e67617000603f0729eaefd11826b45d138532f5bab604649518f0b078b9f80be8c5c206910353c790250f2ee7a6b49aafb3d854e0
6
+ metadata.gz: db545b9c0870ada505a73f5b4420e534f702ebfc4f950c158e64f7bf55d32b51e526fcef3c428dda9e7d2818998431bb7d0fd7fd6c7ba1898d355bd9e8b8461c
7
+ data.tar.gz: d8505d24ce6978a85043fa27a4ba2149ac86be5061819aff27377cb067a9cfb6edc2388a35c7015092603e4b4b0ff784c990807a729829137e8d3922b1627fcd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steppy (1.0.2)
4
+ steppy (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,7 +12,7 @@ module Steppy
12
12
  end
13
13
 
14
14
  def step(method = nil, args = {}, &block)
15
- steps.push(
15
+ steps_cache.push(
16
16
  Steppy.parse_step(method: method, args: args, block: block)
17
17
  )
18
18
  self
@@ -21,12 +21,12 @@ module Steppy
21
21
  alias step_return step
22
22
 
23
23
  def step_if(condition, &block)
24
- steps.push(condition: condition, block: block)
24
+ steps_cache.push(condition: condition, block: block)
25
25
  self
26
26
  end
27
27
 
28
28
  def step_unless(condition, &block)
29
- steps.push(condition: -> { !steppy_run_condition(condition) }, block: block)
29
+ steps_cache.push(condition: -> { !steppy_run_condition(condition) }, block: block)
30
30
  self
31
31
  end
32
32
 
@@ -38,14 +38,14 @@ module Steppy
38
38
  def step_if_else(condition_block, step_steps, args = {})
39
39
  if_step, else_step = step_steps
40
40
 
41
- steps.push Steppy.parse_step(
41
+ steps_cache.push Steppy.parse_step(
42
42
  method: if_step,
43
43
  args: {
44
44
  if: condition_block,
45
45
  }.merge(args)
46
46
  )
47
47
 
48
- steps.push Steppy.parse_step(
48
+ steps_cache.push Steppy.parse_step(
49
49
  method: else_step,
50
50
  args: {
51
51
  unless: condition_block,
@@ -57,17 +57,25 @@ module Steppy
57
57
  step_add_callback(:after, block, key)
58
58
  end
59
59
 
60
+ def step_after_all(&block)
61
+ step_add_callback(:after, block, :all)
62
+ end
63
+
60
64
  def step_before(key = nil, &block)
61
65
  step_add_callback(:before, block, key)
62
66
  end
63
67
 
68
+ def step_before_all(&block)
69
+ step_add_callback(:before, block, :all)
70
+ end
71
+
64
72
  def step_add_callback(type, block, key)
65
- callback_key = key ? key.to_sym : :global
73
+ callback_key = key ? key.to_sym : :each
66
74
  callbacks = step_callbacks[type][callback_key] ||= []
67
75
  callbacks.push(block)
68
76
  end
69
77
 
70
- def steps
78
+ def steps_cache
71
79
  steppy_cache[:steps]
72
80
  end
73
81
 
@@ -82,10 +90,12 @@ module Steppy
82
90
  rescues: [],
83
91
  callbacks: {
84
92
  before: {
85
- global: [],
93
+ all: [],
94
+ each: [],
86
95
  },
87
96
  after: {
88
- global: [],
97
+ all: [],
98
+ each: [],
89
99
  },
90
100
  }
91
101
  )
@@ -8,11 +8,17 @@ module Steppy
8
8
  def steppy(attributes = {}, cache = {})
9
9
  steppy_initialize_cache({ attributes: attributes, prefix: :step }.merge(cache))
10
10
 
11
- if steppy_cache.key?(:block)
11
+ step_run_callbacks(:before, :all, attributes)
12
+
13
+ result = if steppy_cache.key?(:block)
12
14
  instance_exec(&steppy_cache[:block])
13
15
  else
14
16
  steppy_run(steppy_cache)
15
17
  end
18
+
19
+ step_run_callbacks(:after, :all, attributes)
20
+
21
+ result
16
22
  rescue StandardError => exception
17
23
  steppy_rescue exception, steppy_cache[:rescues]
18
24
  end
@@ -135,12 +141,14 @@ module Steppy
135
141
  result
136
142
  end
137
143
 
138
- def step_run_callbacks(type, method, result, args)
144
+ def step_run_callbacks(type, method, result, args = result)
139
145
  callbacks = step_callbacks[type]
140
146
  method_callbacks = callbacks[method] || []
141
147
 
142
- callbacks[:global].each do |callback|
143
- instance_exec(result, args, &callback)
148
+ if method != :all
149
+ callbacks[:each].each do |callback|
150
+ instance_exec(result, args, &callback)
151
+ end
144
152
  end
145
153
 
146
154
  method_callbacks.each do |callback|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Steppy
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steppy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler