stateful_enum 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78d2de46a67e071c7ec7d4b0147d6a52768af7fef8ba81a7454c1f129dcd6b0d
4
- data.tar.gz: 38ddee71fcc5406f6fa8ac93ae582230277173527a5ab32fc8e36a7f9aa15f10
3
+ metadata.gz: 862f0fff7013f98f6f39aa069098e104f7d48bcdefabbb30ca8accf6f817dd49
4
+ data.tar.gz: 645171697753e52e14c87a42df936df727d2b984bfc0dba7f05a18c874667694
5
5
  SHA512:
6
- metadata.gz: f5a4a52fc2a136374e3337d789cf0572296aa79f3724540d166654cffbf9d5c3529dde5b5e4241c0716d0d8a7ba726381e064b1e0996f5c5548813d444c2d926
7
- data.tar.gz: fcd0c04464d71a140c2d7571b6e9732556d4d23b5aa2d52727402220438abd7d1bb266b4f7cd11a8692d1c6a90970a60c89a5a0e23b9cb4fdd0dc85405f73c1d
6
+ metadata.gz: ade6a0c15d35d147bb60f17d7dca8e36c0aa43975d14ca88dc88cf402b3bebd6b4d443b050048a0fbe8d92a339ae2fd966c6aa6220623e385d9df1c401366d8f
7
+ data.tar.gz: b6fd92a9296efb47852956375d73b8c801b63bbf877e4a9612db5f3f74f96ee4930a6cefe12cd635ea667ff43f0875ffebce8307bada70d409ac78f8171095c7
@@ -6,71 +6,87 @@ jobs:
6
6
  build:
7
7
  strategy:
8
8
  matrix:
9
+ ruby_version: [ruby-head, '3.4', '3.3', '3.2', '3.1']
10
+ rails_version: [edge, '8.1', '8.0', '7.2', '7.1', '7.0', '6.1']
11
+
9
12
  include:
10
- - ruby_version: ruby-head
11
- gemfile: gemfiles/Gemfile-rails.edge
12
- allow_failures: 'true'
13
13
  - ruby_version: '3.0'
14
- gemfile: gemfiles/Gemfile-rails.edge
15
- allow_failures: 'true'
16
-
17
- - ruby_version: ruby-head
18
- gemfile: gemfiles/Gemfile-rails.7.0.x
19
- allow_failures: 'true'
20
-
14
+ rails_version: '7.1'
21
15
  - ruby_version: '3.0'
22
- gemfile: gemfiles/Gemfile-rails.7.0.x
23
- - ruby_version: '2.7'
24
- gemfile: gemfiles/Gemfile-rails.7.0.x
25
-
16
+ rails_version: '7.0'
26
17
  - ruby_version: '3.0'
27
- gemfile: gemfiles/Gemfile-rails.6.1.x
28
- - ruby_version: '2.7'
29
- gemfile: gemfiles/Gemfile-rails.6.1.x
30
- - ruby_version: '2.6'
31
- gemfile: gemfiles/Gemfile-rails.6.1.x
18
+ rails_version: '6.1'
19
+ - ruby_version: '3.0'
20
+ rails_version: '6.0'
32
21
 
33
22
  - ruby_version: '2.7'
34
- gemfile: gemfiles/Gemfile-rails.6.0.x
23
+ rails_version: '7.1'
24
+ - ruby_version: '2.7'
25
+ rails_version: '7.0'
26
+ - ruby_version: '2.7'
27
+ rails_version: '6.1'
28
+ - ruby_version: '2.7'
29
+ rails_version: '6.0'
35
30
 
36
31
  - ruby_version: '2.6'
37
- gemfile: gemfiles/Gemfile-rails.5.2.x
38
- - ruby_version: '2.4'
39
- gemfile: gemfiles/Gemfile-rails.5.2.x
40
- - ruby_version: '2.2'
41
- gemfile: gemfiles/Gemfile-rails.5.2.x
42
-
32
+ rails_version: '6.1'
43
33
  - ruby_version: '2.6'
44
- gemfile: gemfiles/Gemfile-rails.5.1.x
45
-
34
+ rails_version: '6.0'
35
+ - ruby_version: '2.6'
36
+ rails_version: '5.2'
37
+ - ruby_version: '2.6'
38
+ rails_version: '5.1'
39
+ - ruby_version: '2.6'
40
+ rails_version: '5.0'
46
41
  - ruby_version: '2.6'
47
- gemfile: gemfiles/Gemfile-rails.5.0.x
42
+ rails_version: '4.2'
43
+ bundler_version: '1'
48
44
 
49
45
  - ruby_version: '2.5'
50
- gemfile: gemfiles/Gemfile-rails.4.2.x
46
+ rails_version: '5.2'
47
+ - ruby_version: '2.5'
48
+ rails_version: '4.2'
49
+ bundler_version: '1'
50
+
51
+ - ruby_version: '2.4'
52
+ rails_version: '5.2'
53
+ - ruby_version: '2.4'
54
+ rails_version: '4.2'
51
55
  bundler_version: '1'
52
56
 
53
57
  - ruby_version: '2.3'
54
- gemfile: gemfiles/Gemfile-rails.4.1.x
58
+ rails_version: '4.1'
55
59
  bundler_version: '1'
56
60
 
61
+ - ruby_version: '2.2'
62
+ rails_version: '5.2'
63
+ bundler_version: '1'
57
64
 
58
- runs-on: ubuntu-latest
65
+ exclude:
66
+ - ruby_version: '3.1'
67
+ rails_version: 'edge'
68
+ - ruby_version: '3.1'
69
+ rails_version: '8.1'
70
+ - ruby_version: '3.1'
71
+ rails_version: '8.0'
59
72
 
60
73
  env:
61
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
74
+ RAILS_VERSION: ${{ matrix.rails_version }}
75
+
76
+ runs-on: ubuntu-24.04
62
77
 
63
78
  steps:
64
- - uses: actions/checkout@v2
79
+ - uses: actions/checkout@v6
65
80
 
66
81
  - uses: ruby/setup-ruby@v1
67
82
  with:
68
83
  ruby-version: "${{ matrix.ruby_version }}"
84
+ rubygems: ${{ matrix.ruby_version < '2.7' && 'default' || 'latest' }}
69
85
  bundler: "${{ matrix.bundler_version }}"
70
86
  bundler-cache: true
71
- continue-on-error: ${{ matrix.allow_failures == 'true' }}
87
+ continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.rails_version == 'edge') || (matrix.allow_failures == 'true') }}
72
88
 
73
89
  - run: sudo apt-get install graphviz
74
90
 
75
91
  - run: bundle exec rake
76
- continue-on-error: ${{ matrix.allow_failures == 'true' }}
92
+ continue-on-error: ${{ (matrix.ruby_version == 'ruby-head') || (matrix.rails_version == 'edge') || (matrix.allow_failures == 'true') }}
data/.gitignore CHANGED
@@ -10,5 +10,7 @@ gemfiles/*.lock
10
10
  /tmp/
11
11
  /log/
12
12
  /test/dummy/log/
13
+ /test/dummy/tmp/
14
+ /test/dummy/**/*.png
13
15
 
14
16
  .byebug_history
data/Gemfile CHANGED
@@ -1,6 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in stateful_enum.gemspec
4
6
  gemspec
5
7
 
6
- gem 'byebug'
8
+ if ENV['RAILS_VERSION'] == 'edge'
9
+ gem 'rails', git: 'https://github.com/rails/rails.git'
10
+ elsif ENV['RAILS_VERSION']
11
+ gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
12
+ if ENV['RAILS_VERSION'] <= '5.0'
13
+ gem 'sqlite3', '< 1.4'
14
+ elsif ENV['RAILS_VERSION'] <= '7.1'
15
+ gem 'sqlite3', '~> 1.4'
16
+ end
17
+ else
18
+ gem 'rails'
19
+ end
20
+
21
+ gem 'selenium-webdriver'
22
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
23
+ gem 'loofah', RUBY_VERSION < '2.5' ? '< 2.21.0' : '>= 0'
24
+
25
+ if RUBY_VERSION >= '3.3'
26
+ gem 'bigdecimal'
27
+ gem 'mutex_m'
28
+ end
29
+
30
+ gem 'benchmark' if RUBY_VERSION >= '3.5'
data/README.md CHANGED
@@ -41,7 +41,7 @@ The stateful_enum gem extends AR::Enum definition to take a block with a similar
41
41
  Example:
42
42
  ```ruby
43
43
  class Bug < ApplicationRecord
44
- enum status: {unassigned: 0, assigned: 1, resolved: 2, closed: 3} do
44
+ enum :status, {unassigned: 0, assigned: 1, resolved: 2, closed: 3} do
45
45
  event :assign do
46
46
  transition :unassigned => :assigned
47
47
  end
@@ -122,6 +122,29 @@ end
122
122
 
123
123
  You can define `before` and `after` event hooks inside of an `event` block.
124
124
 
125
+ Event methods accept arguments (both positional and keyword arguments) that are passed through to the callbacks:
126
+
127
+ ```ruby
128
+ class Bug < ApplicationRecord
129
+ enum :status, {unassigned: 0, assigned: 1, resolved: 2, closed: 3} do
130
+ event :close do
131
+ before do |closed_by:, reason: nil|
132
+ self.closed_by = closed_by
133
+ self.close_reason = reason
134
+ end
135
+
136
+ after do |closed_by:, **|
137
+ Notifier.notify "Bug##{id} was closed by #{closed_by.name}"
138
+ end
139
+
140
+ transition all - [:closed] => :closed
141
+ end
142
+ end
143
+ end
144
+
145
+ @bug.close(closed_by: current_user, reason: 'Duplicate')
146
+ ```
147
+
125
148
  ### Inspecting All Defined Events And Current Possible Events
126
149
 
127
150
  You can get the list of defined events from the model class:
@@ -175,9 +198,9 @@ You can specify relative or absolute output path via environment variable `DEST_
175
198
  * Better Error handling
176
199
 
177
200
 
178
- ## Support Rails Versions
201
+ ## Supported Rails Versions
179
202
 
180
- * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, and 7.1 (edge)
203
+ * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, 7.2, 8.0, 8.1, and 8.2 (edge)
181
204
 
182
205
 
183
206
  ## Contributing
@@ -39,7 +39,7 @@ module StatefulEnum
39
39
  @g.get_node(final) {|n| n['shape'] = 'doublecircle' }
40
40
  end
41
41
 
42
- @g.output png: File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}.png")
42
+ @g.output png: File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}_#{column}.png")
43
43
  end
44
44
 
45
45
  def event(name, &block)
@@ -42,24 +42,23 @@ module StatefulEnum
42
42
  # def assign()
43
43
  detect_enum_conflict! column, value_method_name
44
44
 
45
- # defining callbacks
46
- define_callbacks value_method_name
47
- before.each do |before_callback|
48
- model.set_callback value_method_name, :before, before_callback
49
- end
50
- after.each do |after_callback|
51
- model.set_callback value_method_name, :after, after_callback
52
- end
53
-
54
- define_method value_method_name do
45
+ define_method value_method_name do |*args, **kwargs|
55
46
  to, condition = transitions[send(column).to_sym]
56
47
  #TODO better error
57
48
  if to && (condition.nil? || instance_exec(&condition))
58
49
  #TODO transaction?
59
- run_callbacks value_method_name do
60
- original_method = self.class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
61
- original_method.bind(self).call
50
+ before.each do |before_callback|
51
+ instance_exec(*args, **kwargs, &before_callback)
62
52
  end
53
+
54
+ original_method = self.class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
55
+ ret = original_method.bind(self).call
56
+
57
+ after.each do |after_callback|
58
+ instance_exec(*args, **kwargs, &after_callback)
59
+ end
60
+
61
+ ret
63
62
  else
64
63
  false
65
64
  end
@@ -67,8 +66,8 @@ module StatefulEnum
67
66
 
68
67
  # def assign!()
69
68
  detect_enum_conflict! column, "#{value_method_name}!"
70
- define_method "#{value_method_name}!" do
71
- send(value_method_name) || raise('Invalid transition')
69
+ define_method "#{value_method_name}!" do |*args, **kwargs|
70
+ send(value_method_name, *args, **kwargs) || raise('Invalid transition')
72
71
  end
73
72
 
74
73
  # def can_assign?()
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StatefulEnum
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateful_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2021-12-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -109,15 +108,6 @@ files:
109
108
  - Rakefile
110
109
  - bin/console
111
110
  - bin/setup
112
- - gemfiles/Gemfile-rails.4.1.x
113
- - gemfiles/Gemfile-rails.4.2.x
114
- - gemfiles/Gemfile-rails.5.0.x
115
- - gemfiles/Gemfile-rails.5.1.x
116
- - gemfiles/Gemfile-rails.5.2.x
117
- - gemfiles/Gemfile-rails.6.0.x
118
- - gemfiles/Gemfile-rails.6.1.x
119
- - gemfiles/Gemfile-rails.7.0.x
120
- - gemfiles/Gemfile-rails.edge
121
111
  - lib/generators/stateful_enum/graph_generator.rb
122
112
  - lib/generators/stateful_enum/plantuml_generator.rb
123
113
  - lib/stateful_enum.rb
@@ -131,7 +121,6 @@ homepage: https://github.com/amatsuda/stateful_enum
131
121
  licenses:
132
122
  - MIT
133
123
  metadata: {}
134
- post_install_message:
135
124
  rdoc_options: []
136
125
  require_paths:
137
126
  - lib
@@ -146,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
135
  - !ruby/object:Gem::Version
147
136
  version: '0'
148
137
  requirements: []
149
- rubygems_version: 3.1.6
150
- signing_key:
138
+ rubygems_version: 4.0.3
151
139
  specification_version: 4
152
140
  summary: A state machine plugin on top of ActiveRecord::Enum
153
141
  test_files: []
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 4.1.0'
6
- gem 'sqlite3', '~> 1.3.6'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3', '~> 1.3.6'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 5.0.0'
6
- gem 'sqlite3', '~> 1.3.6'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 5.1.0'
6
- gem 'sqlite3', '~> 1.3.6'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', git: 'https://github.com/rails/rails/', branch: '5-2-stable'
6
- gem 'sqlite3', '~> 1.3.6'
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 6.0.0'
6
- gem 'sqlite3', '~> 1.4'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 6.1.0'
6
- gem 'sqlite3', '~> 1.4'
7
- gem 'selenium-webdriver'
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 7.0.0'
6
- gem 'sqlite3', '~> 1.4'
7
- gem 'selenium-webdriver'
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- git_source(:github) do |repo_name|
4
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
- "https://github.com/#{repo_name}.git"
6
- end
7
-
8
- gemspec path: '..'
9
-
10
- github 'rails/rails' do
11
- gem 'rails'
12
- end
13
- gem 'sqlite3'
14
- gem 'selenium-webdriver'