nxt_state_machine 0.1.10 → 0.1.11

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: c131c9fdbce2f5a605ecdfa39a63e0ea7ef21dda4a2f9600e790e56e0c4444a0
4
- data.tar.gz: 49689f892d2262705c0248c05d7b0d6612b31255fb3da130494cbe200f105d83
3
+ metadata.gz: bc37e9d88ae62233544b548a5085fe81f67be0957f498ebf0490a191ac37af8d
4
+ data.tar.gz: b999a6f14950de8f1bcca65082ff6c7ff9d7e61d29aeb0323e65d126502a5cdc
5
5
  SHA512:
6
- metadata.gz: e176a5b1205cbfb3d901f5c7c768971b64eea974f613d4a298430f81473c13dc3852f6e4eb021d4fd1eb98cba2fd8b9d69a4671a64b0c9a5e1f2e46cc20c7580
7
- data.tar.gz: 9dff03854918e23c0c0dc9ae00c55116a4244a314f0799ce2e3c81841d257e9406cff25eb68833c6c32a99e8d4c562ff1609d22fb307c63f44a12165f47a2997
6
+ metadata.gz: bd80fa569f48c50ab81bc1380e1683d4d646a128ed5bae016d46a4c8263411f0de0bdf39934a480fdf55d0849fc516201444f2e2eecdf75ee903f45df5373661
7
+ data.tar.gz: af346178ff3e9321a4592862babffe717aceeabde96aa625768bd163070c99bad477514a9b2d4aa3b16553ebf3886039beed0748fee67a60c7cc4f96ed66b1dd
data/.circleci/config.yml CHANGED
@@ -1,15 +1,13 @@
1
- # Ruby CircleCI 2.0 configuration file
2
- #
3
- # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
- #
5
- version: 2
1
+ version: 2.1
2
+
3
+ orbs:
4
+ ruby: circleci/ruby@2.0.1
5
+ coveralls: coveralls/coveralls@1.0.6
6
+
6
7
  jobs:
7
8
  build:
8
9
  docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby:2.6.5-node
11
- environment:
12
- BUNDLER_VERSION: 2.0.2
10
+ - image: 'cimg/ruby:3.2.2-node'
13
11
 
14
12
  working_directory: ~/repo
15
13
 
@@ -17,46 +15,12 @@ jobs:
17
15
  - checkout
18
16
 
19
17
  - run:
20
- name: Install apt dependencies
18
+ name: Install apt dependencies (graphviz)
21
19
  command: |
22
20
  sudo apt update -q \
23
21
  && sudo apt upgrade -q \
24
22
  && sudo apt install -qq graphviz
25
- # Download and cache dependencies
26
- - restore_cache:
27
- keys:
28
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
29
-
30
- - run: gem install bundler --version $BUNDLER_VERSION
31
-
32
- - run:
33
- name: install dependencies
34
- command: |
35
- bundle install --jobs=4 --retry=3 --path vendor/bundle
36
-
37
- - save_cache:
38
- paths:
39
- - ./vendor/bundle
40
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
41
-
42
- # run tests!
43
- - run:
44
- name: run tests
45
- command: |
46
- mkdir /tmp/test-results
47
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
48
- circleci tests split --split-by=timings)"
49
-
50
- bundle exec rspec \
51
- --format progress \
52
- --format RspecJunitFormatter \
53
- --out /tmp/test-results/rspec.xml \
54
- --format progress \
55
- $TEST_FILES
56
-
57
- # collect reports
58
- - store_test_results:
59
- path: /tmp/test-results
60
- - store_artifacts:
61
- path: /tmp/test-results
62
- destination: test-results
23
+ - ruby/install-deps:
24
+ key: gems-v2
25
+ include-branch-in-cache-key: false
26
+ - ruby/rspec-test
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.3
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.1.11 2023-06-29
2
+
3
+ ### Added
4
+ - Added `state_machine.event_methods`
5
+
6
+ [Compare v0.1.10...v0.1.11](https://github.com/nxt-insurance/nxt_state_machine/compare/v0.1.10...v0.1.11)
7
+
1
8
  # v0.1.10 2021-07-19
2
9
 
3
10
  ### Added
data/Gemfile.lock CHANGED
@@ -1,59 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_state_machine (0.1.10)
4
+ nxt_state_machine (0.1.11)
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.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)
11
+ activemodel (7.0.5.1)
12
+ activesupport (= 7.0.5.1)
13
+ activerecord (7.0.5.1)
14
+ activemodel (= 7.0.5.1)
15
+ activesupport (= 7.0.5.1)
16
+ activesupport (7.0.5.1)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
22
21
  coderay (1.1.3)
23
- concurrent-ruby (1.1.9)
24
- diff-lcs (1.4.4)
25
- i18n (1.8.10)
22
+ concurrent-ruby (1.2.2)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.14.1)
26
25
  concurrent-ruby (~> 1.0)
27
26
  method_source (1.0.0)
28
- minitest (5.14.4)
27
+ mini_portile2 (2.8.2)
28
+ minitest (5.18.1)
29
29
  nxt_registry (0.3.10)
30
30
  activesupport
31
- pry (0.14.1)
31
+ pry (0.14.2)
32
32
  coderay (~> 1.1)
33
33
  method_source (~> 1.0)
34
34
  rake (12.3.3)
35
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)
36
+ rspec (3.12.0)
37
+ rspec-core (~> 3.12.0)
38
+ rspec-expectations (~> 3.12.0)
39
+ rspec-mocks (~> 3.12.0)
40
+ rspec-core (3.12.2)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-expectations (3.12.3)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-mocks (3.10.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-mocks (3.12.5)
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.10.0)
48
- rspec-support (3.10.0)
49
- rspec_junit_formatter (0.4.1)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-support (3.12.1)
49
+ rspec_junit_formatter (0.6.0)
50
50
  rspec-core (>= 2, < 4, != 2.12.0)
51
51
  ruby-graphviz (1.2.5)
52
52
  rexml
53
- sqlite3 (1.4.2)
54
- tzinfo (2.0.4)
53
+ sqlite3 (1.6.3)
54
+ mini_portile2 (~> 2.8.0)
55
+ tzinfo (2.0.6)
55
56
  concurrent-ruby (~> 1.0)
56
- zeitwerk (2.4.2)
57
57
 
58
58
  PLATFORMS
59
59
  ruby
data/README.md CHANGED
@@ -181,7 +181,14 @@ class Article < ApplicationRecord
181
181
  end
182
182
  ```
183
183
 
184
- You can also navigate between states
184
+ You can retrieve a list of states using the `states` method:
185
+
186
+ ```rb
187
+ states = Article.state_machine.states # returns a NxtStateMachine::StateRegistry instance
188
+ states.keys # ["draft", "written", "submitted", "approved", "published", "rejected", "deleted"]
189
+ ```
190
+
191
+ You can also navigate between states:
185
192
 
186
193
  ```ruby
187
194
  state.next # will give you the next state in the order they have been registered
@@ -192,6 +199,7 @@ state.index # gives you the index of the state in the registry
192
199
  # You can also set indexes manually by passing in indexes when defining states. Make sure they are in order!
193
200
  ```
194
201
 
202
+
195
203
  ### Events
196
204
 
197
205
  Once you have defined your states you can define events and their transitions. Events trigger state transitions based
@@ -241,15 +249,27 @@ article.approve(approved_at: Time.current)
241
249
  article.approve!(approved_at: Time.current)
242
250
  ```
243
251
 
244
- **NOTE:** Transitions run in transactions that acquire a lock to prevent concurrency issues per default.
245
- Transactions will be rolled back in case of an exception or if your target cannot be saved due to validation errors.
252
+ > **Note**:
253
+ >
254
+ > By default, transitions run in transactions that acquire a lock to prevent concurrency issues.
255
+ Transactions will be rolled back if an exception occurs or if your target cannot be saved due to validation errors.
246
256
  The state is set back to the state before the transition! If you try to transition on records with unpersisted changes
247
257
  you will get a `RuntimeError: Locking a record with unpersisted changes is not supported.` error saying something
248
258
  like `Use :save to persist the changes, or :reload to discard them explicitly.` since it's not possible to acquire a
249
- lock on modified records. You can also switch of locking and transactions for events by passing in the `lock_transitions: false`
259
+ lock on modified records.
260
+ >
261
+ > You can switch off locking and transactions for events by passing in the `lock_transitions: false`
250
262
  option when defining an event or globally on the state machine with the `lock_transitions: false` option. Currently
251
263
  there is no option to toggle locking at runtime.
252
264
 
265
+
266
+ You can retrieve a list of event methods with `event_methods`:
267
+
268
+ ```rb
269
+ Article.state_machine.event_methods
270
+ # => [:write, :submit, :approve, :publish, :reject, :delete, :write!, :submit!, :approve!, :publish!, :reject!, :delete!]
271
+ ```
272
+
253
273
  ### Transitions
254
274
 
255
275
  When your transition takes arguments other than keyword arguments, it will always be passed the transition object itself
@@ -75,6 +75,13 @@ module NxtStateMachine
75
75
  states.values.map(&:enum)
76
76
  end
77
77
 
78
+ def event_methods
79
+ event_names = events.keys
80
+ event_names_with_bang = event_names.map { |e| e + '!' }
81
+
82
+ (event_names + event_names_with_bang).map(&:to_sym)
83
+ end
84
+
78
85
  alias_method :all_states, :any_state
79
86
 
80
87
  def all_states_except(*excluded)
@@ -1,3 +1,3 @@
1
1
  module NxtStateMachine
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-07-19 00:00:00.000000000 Z
14
+ date: 2023-06-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -152,7 +152,6 @@ files:
152
152
  - ".gitignore"
153
153
  - ".rspec"
154
154
  - ".ruby-version"
155
- - ".travis.yml"
156
155
  - CHANGELOG.md
157
156
  - Gemfile
158
157
  - Gemfile.lock
@@ -220,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
219
  - !ruby/object:Gem::Version
221
220
  version: '0'
222
221
  requirements: []
223
- rubygems_version: 3.1.6
222
+ rubygems_version: 3.4.10
224
223
  signing_key:
225
224
  specification_version: 4
226
225
  summary: A rich but straight forward state machine library
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- before_install: gem install bundler -v 2.0.2