nxt_state_machine 0.1.9 → 0.1.10

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: 6128e445380f2ed2b836b4c23ed58556efd2ff0728add08c2cbd45e97812e068
4
- data.tar.gz: 05c8861e99afefec3c654366050b225d7a93c10ff984e508cd14d6345b1d0ff3
3
+ metadata.gz: c131c9fdbce2f5a605ecdfa39a63e0ea7ef21dda4a2f9600e790e56e0c4444a0
4
+ data.tar.gz: 49689f892d2262705c0248c05d7b0d6612b31255fb3da130494cbe200f105d83
5
5
  SHA512:
6
- metadata.gz: d3038d32da3a7bfa5a49b4537e7c6f163259ddd0f3d2b48a05bfa838021350f648d75bfc493125529c9e1374dc34aa2c9abe94325790fe4ba82a09f01e2afdc8
7
- data.tar.gz: 64178102f125d3b180f31b1a0bbebd766226b44351bbef906d907cc6339f2ff213c743c51b52238706827cfd597e410b828eb0824f8a4747f363c9b2b79a0ce9
6
+ metadata.gz: e176a5b1205cbfb3d901f5c7c768971b64eea974f613d4a298430f81473c13dc3852f6e4eb021d4fd1eb98cba2fd8b9d69a4671a64b0c9a5e1f2e46cc20c7580
7
+ data.tar.gz: 9dff03854918e23c0c0dc9ae00c55116a4244a314f0799ce2e3c81841d257e9406cff25eb68833c6c32a99e8d4c562ff1609d22fb307c63f44a12165f47a2997
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.7.3
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
- # v0.1.9 2020-09-23
1
+ # v0.1.10 2021-07-19
2
2
 
3
3
  ### Added
4
4
 
5
+ - Transition now optionally get passed the transition object that allows to access transition arguments and options.
6
+
7
+ [Compare v0.1.9...v0.1.10](https://github.com/nxt-insurance/nxt_state_machine/compare/v0.1.9...v0.1.10)
8
+
9
+
10
+ # v0.1.9 2020-09-23
11
+
12
+ ### Added
13
+
5
14
  - Allow to toggle locking of transitions for active record adapter per event or globally
6
15
 
7
16
  [Compare v0.1.8...v0.1.9](https://github.com/nxt-insurance/nxt_state_machine/compare/v0.1.8...v0.1.9)
data/Gemfile.lock CHANGED
@@ -1,60 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_state_machine (0.1.9)
4
+ nxt_state_machine (0.1.10)
5
5
  activesupport
6
6
  nxt_registry (~> 0.3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.3.3)
12
- activesupport (= 6.0.3.3)
13
- activerecord (6.0.3.3)
14
- activemodel (= 6.0.3.3)
15
- activesupport (= 6.0.3.3)
16
- activesupport (6.0.3.3)
11
+ activemodel (6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
+ activerecord (6.1.3.2)
14
+ activemodel (= 6.1.3.2)
15
+ activesupport (= 6.1.3.2)
16
+ activesupport (6.1.3.2)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2, >= 2.2.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
22
  coderay (1.1.3)
23
- concurrent-ruby (1.1.7)
23
+ concurrent-ruby (1.1.9)
24
24
  diff-lcs (1.4.4)
25
- i18n (1.8.5)
25
+ i18n (1.8.10)
26
26
  concurrent-ruby (~> 1.0)
27
27
  method_source (1.0.0)
28
- minitest (5.14.2)
29
- nxt_registry (0.3.2)
28
+ minitest (5.14.4)
29
+ nxt_registry (0.3.10)
30
30
  activesupport
31
- pry (0.13.1)
31
+ pry (0.14.1)
32
32
  coderay (~> 1.1)
33
33
  method_source (~> 1.0)
34
34
  rake (12.3.3)
35
- rexml (3.2.4)
36
- rspec (3.9.0)
37
- rspec-core (~> 3.9.0)
38
- rspec-expectations (~> 3.9.0)
39
- rspec-mocks (~> 3.9.0)
40
- rspec-core (3.9.2)
41
- rspec-support (~> 3.9.3)
42
- rspec-expectations (3.9.2)
35
+ rexml (3.2.5)
36
+ rspec (3.10.0)
37
+ rspec-core (~> 3.10.0)
38
+ rspec-expectations (~> 3.10.0)
39
+ rspec-mocks (~> 3.10.0)
40
+ rspec-core (3.10.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-expectations (3.10.0)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.9.0)
45
- rspec-mocks (3.9.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-mocks (3.10.0)
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.9.0)
48
- rspec-support (3.9.3)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-support (3.10.0)
49
49
  rspec_junit_formatter (0.4.1)
50
50
  rspec-core (>= 2, < 4, != 2.12.0)
51
51
  ruby-graphviz (1.2.5)
52
52
  rexml
53
53
  sqlite3 (1.4.2)
54
- thread_safe (0.3.6)
55
- tzinfo (1.2.7)
56
- thread_safe (~> 0.1)
57
- zeitwerk (2.4.0)
54
+ tzinfo (2.0.4)
55
+ concurrent-ruby (~> 1.0)
56
+ zeitwerk (2.4.2)
58
57
 
59
58
  PLATFORMS
60
59
  ruby
data/README.md CHANGED
@@ -298,7 +298,7 @@ event :approve do
298
298
 
299
299
  after_transition from: %i[written submitted deleted], to: :approved, run: :call_me_back
300
300
 
301
- around_transition from: any_state, to: :approved do |block|
301
+ around_transition from: any_state, to: :approved do |block, _transition|
302
302
  # Note that around transition callbacks get passed a proc object that you have to call
303
303
  puts 'around transition enter'
304
304
  block.call
@@ -312,6 +312,16 @@ event :approve do
312
312
  end
313
313
  ```
314
314
 
315
+ In callbacks you also have access to the current transition object. Through it you also have access to the arguments
316
+ and options that have been passed in when the transition was triggered:
317
+
318
+ ```ruby
319
+ before_transition from: any_state, to: :processed do |transition|
320
+ puts transition.arguments # => :arg_1, :arg_2 what was passed to the process!(:arg_1, :arg_2)
321
+ puts transition.options # => { arg_1: 'arg 1', arg_2: 'arg 2' } what was passed to the process!(arg_1: 'arg 1', arg_2: 'arg 2')
322
+ end
323
+ ```
324
+
315
325
  ### Error Callbacks
316
326
 
317
327
  You can also register callbacks that run in case of an error occurs. By defining the error class you can restrict
@@ -2,7 +2,7 @@ module NxtStateMachine
2
2
  class Transition
3
3
  include Transition::Interface
4
4
 
5
- def initialize(name, event:, from:, to:, state_machine:, context:, set_state_method:, &block)
5
+ def initialize(name, event:, from:, to:, state_machine:, context:, set_state_method:, arguments:, options:, &block)
6
6
  @name = name
7
7
  @event = event
8
8
  @from = state_machine.states.resolve!(from)
@@ -11,10 +11,12 @@ module NxtStateMachine
11
11
  @set_state_method = set_state_method
12
12
  @context = context
13
13
  @block = block
14
+ @arguments = arguments
15
+ @options = options
14
16
  @result = nil
15
17
  end
16
18
 
17
- attr_reader :name, :from, :to, :block, :event, :result
19
+ attr_reader :name, :from, :to, :block, :event, :result, :arguments, :options
18
20
 
19
21
  # This triggers the set state method
20
22
  def trigger
@@ -25,7 +25,9 @@ module NxtStateMachine
25
25
  state_machine: state_machine,
26
26
  context: context,
27
27
  event: event,
28
- set_state_method: set_state_method
28
+ set_state_method: set_state_method,
29
+ arguments: args,
30
+ options: opts
29
31
  }
30
32
 
31
33
  transition = Transition.new(event.name, **options)
@@ -33,8 +35,12 @@ module NxtStateMachine
33
35
  if block
34
36
  # if the transition takes a block we make it available through a proxy on the transition itself!
35
37
  transition.send(:block=, Proc.new do
36
- # if the block takes arguments we always pass the transition as the first one
37
- args.prepend(transition) if block.arity > 0
38
+ # if the transition block takes arguments we always pass the transition itself as the first argument
39
+ # callbacks also get passed the transition object in case they take an argument and can access args and
40
+ # options passed to the transition when invoked through that transition object
41
+ if block.arity > 0
42
+ args = [transition] + args
43
+ end
38
44
  context.instance_exec(*args, **opts, &block)
39
45
  end)
40
46
  end
@@ -1,3 +1,3 @@
1
1
  module NxtStateMachine
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
8
8
  - Nils Sommer
9
9
  - Raphael Kallensee
10
10
  - Lütfi Demirci
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2020-09-30 00:00:00.000000000 Z
14
+ date: 2021-07-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -205,7 +205,7 @@ metadata:
205
205
  allowed_push_host: https://rubygems.org
206
206
  homepage_uri: https://github.com/nxt-insurance/nxt_state_machine
207
207
  source_code_uri: https://github.com/nxt-insurance/nxt_state_machine
208
- post_install_message:
208
+ post_install_message:
209
209
  rdoc_options: []
210
210
  require_paths:
211
211
  - lib
@@ -220,8 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubygems_version: 3.0.3
224
- signing_key:
223
+ rubygems_version: 3.1.6
224
+ signing_key:
225
225
  specification_version: 4
226
226
  summary: A rich but straight forward state machine library
227
227
  test_files: []