nxt_state_machine 0.1.10 → 0.1.12

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: 413f20677e821a50eaa46266005d902f1e9e32590e1456e49847e92a257857c0
4
+ data.tar.gz: c4e1069379acacf327ab01922de03fdd3e16090d73a29e6c31486a78d4d22e26
5
5
  SHA512:
6
- metadata.gz: e176a5b1205cbfb3d901f5c7c768971b64eea974f613d4a298430f81473c13dc3852f6e4eb021d4fd1eb98cba2fd8b9d69a4671a64b0c9a5e1f2e46cc20c7580
7
- data.tar.gz: 9dff03854918e23c0c0dc9ae00c55116a4244a314f0799ce2e3c81841d257e9406cff25eb68833c6c32a99e8d4c562ff1609d22fb307c63f44a12165f47a2997
6
+ metadata.gz: 06da24e5f64c4a5575ffdf1a5ffc5761554758750b5e2d6c6a2012df7df7950376a6c66e46b82476848529f6bd893b26c4e108a0e1fe0585f0f813ab3f128843
7
+ data.tar.gz: 02c7131e6230181cdfcbb2ada9f8e995674ba4472ebe19482ed0f09a8185094446e7b3ac43ebf3840a35156077038404a632bd84846dcdf82729b73033d9b950
data/.circleci/config.yml CHANGED
@@ -1,15 +1,12 @@
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
+
6
6
  jobs:
7
7
  build:
8
8
  docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby:2.6.5-node
11
- environment:
12
- BUNDLER_VERSION: 2.0.2
9
+ - image: 'cimg/ruby:3.3.4-node'
13
10
 
14
11
  working_directory: ~/repo
15
12
 
@@ -17,46 +14,12 @@ jobs:
17
14
  - checkout
18
15
 
19
16
  - run:
20
- name: Install apt dependencies
17
+ name: Install apt dependencies (graphviz)
21
18
  command: |
22
19
  sudo apt update -q \
23
20
  && sudo apt upgrade -q \
24
21
  && 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
22
+ - ruby/install-deps:
23
+ key: gems-v2
24
+ include-branch-in-cache-key: false
25
+ - ruby/rspec-test
data/.gitignore CHANGED
@@ -1,7 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
- /coverage/
5
4
  /doc/
6
5
  /pkg/
7
6
  /spec/reports/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.3
1
+ 3.3.4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # v0.1.12 2024-07-31
2
+
3
+ ### Changed
4
+ - Remove Coveralls remainings
5
+ - Upgrade dependencies
6
+
7
+ [Compare v0.1.11...v0.1.12](https://github.com/nxt-insurance/nxt_state_machine/compare/v0.1.11...v0.1.12)
8
+
9
+ # v0.1.11 2023-06-29
10
+
11
+ ### Added
12
+ - Added `state_machine.event_methods`
13
+
14
+ [Compare v0.1.10...v0.1.11](https://github.com/nxt-insurance/nxt_state_machine/compare/v0.1.10...v0.1.11)
15
+
1
16
  # v0.1.10 2021-07-19
2
17
 
3
18
  ### Added
data/Gemfile.lock CHANGED
@@ -1,59 +1,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_state_machine (0.1.10)
4
+ nxt_state_machine (0.1.12)
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.1.3.4)
12
+ activesupport (= 7.1.3.4)
13
+ activerecord (7.1.3.4)
14
+ activemodel (= 7.1.3.4)
15
+ activesupport (= 7.1.3.4)
16
+ timeout (>= 0.4.0)
17
+ activesupport (7.1.3.4)
18
+ base64
19
+ bigdecimal
17
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ connection_pool (>= 2.2.5)
22
+ drb
18
23
  i18n (>= 1.6, < 2)
19
24
  minitest (>= 5.1)
25
+ mutex_m
20
26
  tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
27
+ base64 (0.2.0)
28
+ bigdecimal (3.1.8)
22
29
  coderay (1.1.3)
23
- concurrent-ruby (1.1.9)
24
- diff-lcs (1.4.4)
25
- i18n (1.8.10)
30
+ concurrent-ruby (1.3.3)
31
+ connection_pool (2.4.1)
32
+ diff-lcs (1.5.1)
33
+ drb (2.2.1)
34
+ i18n (1.14.5)
26
35
  concurrent-ruby (~> 1.0)
27
- method_source (1.0.0)
28
- minitest (5.14.4)
36
+ method_source (1.1.0)
37
+ minitest (5.24.1)
38
+ mutex_m (0.2.0)
29
39
  nxt_registry (0.3.10)
30
40
  activesupport
31
- pry (0.14.1)
41
+ pry (0.14.2)
32
42
  coderay (~> 1.1)
33
43
  method_source (~> 1.0)
34
- rake (12.3.3)
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)
44
+ rake (13.2.1)
45
+ rexml (3.3.2)
46
+ strscan
47
+ rspec (3.13.0)
48
+ rspec-core (~> 3.13.0)
49
+ rspec-expectations (~> 3.13.0)
50
+ rspec-mocks (~> 3.13.0)
51
+ rspec-core (3.13.0)
52
+ rspec-support (~> 3.13.0)
53
+ rspec-expectations (3.13.1)
43
54
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.10.0)
45
- rspec-mocks (3.10.0)
55
+ rspec-support (~> 3.13.0)
56
+ rspec-mocks (3.13.1)
46
57
  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)
58
+ rspec-support (~> 3.13.0)
59
+ rspec-support (3.13.1)
60
+ rspec_junit_formatter (0.6.0)
50
61
  rspec-core (>= 2, < 4, != 2.12.0)
51
62
  ruby-graphviz (1.2.5)
52
63
  rexml
53
- sqlite3 (1.4.2)
54
- tzinfo (2.0.4)
64
+ sqlite3 (1.4.4)
65
+ strscan (3.1.0)
66
+ timeout (0.4.1)
67
+ tzinfo (2.0.6)
55
68
  concurrent-ruby (~> 1.0)
56
- zeitwerk (2.4.2)
57
69
 
58
70
  PLATFORMS
59
71
  ruby
@@ -63,11 +75,11 @@ DEPENDENCIES
63
75
  bundler (~> 2.0)
64
76
  nxt_state_machine!
65
77
  pry
66
- rake (~> 12.0)
78
+ rake (~> 13.2)
67
79
  rspec (~> 3.0)
68
80
  rspec_junit_formatter
69
81
  ruby-graphviz
70
- sqlite3
82
+ sqlite3 (~> 1.4.4)
71
83
 
72
84
  BUNDLED WITH
73
- 2.1.4
85
+ 2.5.15
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.12'
3
3
  end
@@ -38,10 +38,10 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "nxt_registry", "~> 0.3.0"
39
39
 
40
40
  spec.add_development_dependency "bundler", "~> 2.0"
41
- spec.add_development_dependency "rake", "~> 12.0"
41
+ spec.add_development_dependency "rake", "~> 13.2"
42
42
  spec.add_development_dependency "rspec", "~> 3.0"
43
43
  spec.add_development_dependency "pry"
44
44
  spec.add_development_dependency "activerecord"
45
- spec.add_development_dependency "sqlite3"
45
+ spec.add_development_dependency "sqlite3", "~> 1.4.4"
46
46
  spec.add_development_dependency "ruby-graphviz"
47
47
  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.12
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: 2024-07-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -61,14 +61,14 @@ dependencies:
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: '12.0'
64
+ version: '13.2'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: '12.0'
71
+ version: '13.2'
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: rspec
74
74
  requirement: !ruby/object:Gem::Requirement
@@ -115,16 +115,16 @@ dependencies:
115
115
  name: sqlite3
116
116
  requirement: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ">="
118
+ - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: 1.4.4
121
121
  type: :development
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
- - - ">="
125
+ - - "~>"
126
126
  - !ruby/object:Gem::Version
127
- version: '0'
127
+ version: 1.4.4
128
128
  - !ruby/object:Gem::Dependency
129
129
  name: ruby-graphviz
130
130
  requirement: !ruby/object:Gem::Requirement
@@ -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.5.11
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