stateful_enum 0.3.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +76 -0
- data/README.md +35 -2
- data/Rakefile +0 -8
- data/gemfiles/Gemfile-rails.4.1.x +2 -4
- data/gemfiles/Gemfile-rails.4.2.x +2 -4
- data/gemfiles/Gemfile-rails.5.0.x +6 -0
- data/gemfiles/Gemfile-rails.5.1.x +6 -0
- data/gemfiles/Gemfile-rails.5.2.x +6 -0
- data/gemfiles/Gemfile-rails.6.0.x +6 -0
- data/gemfiles/Gemfile-rails.6.1.x +7 -0
- data/gemfiles/Gemfile-rails.7.0.x +7 -0
- data/gemfiles/Gemfile-rails.edge +14 -0
- data/lib/generators/stateful_enum/graph_generator.rb +3 -2
- data/lib/generators/stateful_enum/plantuml_generator.rb +70 -0
- data/lib/stateful_enum/active_record_extension.rb +25 -7
- data/lib/stateful_enum/machine.rb +45 -34
- data/lib/stateful_enum/railtie.rb +6 -2
- data/lib/stateful_enum/state_inspection.rb +44 -0
- data/lib/stateful_enum/version.rb +1 -1
- metadata +16 -9
- data/.travis.yml +0 -33
- data/gemfiles/Gemfile-rails.5.0.0 +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78d2de46a67e071c7ec7d4b0147d6a52768af7fef8ba81a7454c1f129dcd6b0d
|
4
|
+
data.tar.gz: 38ddee71fcc5406f6fa8ac93ae582230277173527a5ab32fc8e36a7f9aa15f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a4a52fc2a136374e3337d789cf0572296aa79f3724540d166654cffbf9d5c3529dde5b5e4241c0716d0d8a7ba726381e064b1e0996f5c5548813d444c2d926
|
7
|
+
data.tar.gz: fcd0c04464d71a140c2d7571b6e9732556d4d23b5aa2d52727402220438abd7d1bb266b4f7cd11a8692d1c6a90970a60c89a5a0e23b9cb4fdd0dc85405f73c1d
|
@@ -0,0 +1,76 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
include:
|
10
|
+
- ruby_version: ruby-head
|
11
|
+
gemfile: gemfiles/Gemfile-rails.edge
|
12
|
+
allow_failures: 'true'
|
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
|
+
|
21
|
+
- 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
|
+
|
26
|
+
- 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
|
32
|
+
|
33
|
+
- ruby_version: '2.7'
|
34
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
35
|
+
|
36
|
+
- 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
|
+
|
43
|
+
- ruby_version: '2.6'
|
44
|
+
gemfile: gemfiles/Gemfile-rails.5.1.x
|
45
|
+
|
46
|
+
- ruby_version: '2.6'
|
47
|
+
gemfile: gemfiles/Gemfile-rails.5.0.x
|
48
|
+
|
49
|
+
- ruby_version: '2.5'
|
50
|
+
gemfile: gemfiles/Gemfile-rails.4.2.x
|
51
|
+
bundler_version: '1'
|
52
|
+
|
53
|
+
- ruby_version: '2.3'
|
54
|
+
gemfile: gemfiles/Gemfile-rails.4.1.x
|
55
|
+
bundler_version: '1'
|
56
|
+
|
57
|
+
|
58
|
+
runs-on: ubuntu-latest
|
59
|
+
|
60
|
+
env:
|
61
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
62
|
+
|
63
|
+
steps:
|
64
|
+
- uses: actions/checkout@v2
|
65
|
+
|
66
|
+
- uses: ruby/setup-ruby@v1
|
67
|
+
with:
|
68
|
+
ruby-version: "${{ matrix.ruby_version }}"
|
69
|
+
bundler: "${{ matrix.bundler_version }}"
|
70
|
+
bundler-cache: true
|
71
|
+
continue-on-error: ${{ matrix.allow_failures == 'true' }}
|
72
|
+
|
73
|
+
- run: sudo apt-get install graphviz
|
74
|
+
|
75
|
+
- run: bundle exec rake
|
76
|
+
continue-on-error: ${{ matrix.allow_failures == 'true' }}
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# StatefulEnum [![Build Status](https://
|
1
|
+
# StatefulEnum [![Build Status](https://github.com/amatsuda/stateful_enum/actions/workflows/main.yml/badge.svg)](https://github.com/amatsuda/stateful_enum/actions)
|
2
2
|
|
3
3
|
stateful_enum is a state machine gem built on top of ActiveRecord's built-in ActiveRecord::Enum.
|
4
4
|
|
@@ -105,6 +105,7 @@ There are a few important details to note regarding this feature:
|
|
105
105
|
* The "from" states and the "to" states should both be given in Symbols.
|
106
106
|
* The "from" state can be multiple states, in which case the key can be given as an Array of states, as shown in the usage example.
|
107
107
|
* The "from" state can be `all` that means all defined states.
|
108
|
+
* The "from" state can be an exception of Array of states, in this case the key can be a subtraction of `all` with the state to be excluded, as shown in the usage example.
|
108
109
|
|
109
110
|
### :if and :unless Condition
|
110
111
|
|
@@ -121,6 +122,38 @@ end
|
|
121
122
|
|
122
123
|
You can define `before` and `after` event hooks inside of an `event` block.
|
123
124
|
|
125
|
+
### Inspecting All Defined Events And Current Possible Events
|
126
|
+
|
127
|
+
You can get the list of defined events from the model class:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
Bug.stateful_enum.events
|
131
|
+
#=> an Array of all defined StatefulEnum::Machine::Event objects
|
132
|
+
```
|
133
|
+
|
134
|
+
And you can get the list of possible event definitions from the model instance:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
Bug.new(status: :assigned).stateful_enum.possible_events
|
138
|
+
#=> an Array of StatefulEnum::Machine::Event objects that are callable from the receiver object
|
139
|
+
```
|
140
|
+
|
141
|
+
Maybe what you really need for your app is the list of possible event "names":
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
Bug.new(status: :assigned).stateful_enum.possible_event_names
|
145
|
+
#=> [:resolve, :close]
|
146
|
+
```
|
147
|
+
|
148
|
+
You can get the list of next possible state names as well:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
Bug.new(status: :assigned).stateful_enum.possible_states
|
152
|
+
#=> [:resolved, :closed]
|
153
|
+
```
|
154
|
+
|
155
|
+
These features would help some kind of metaprogramming over state transitions.
|
156
|
+
|
124
157
|
|
125
158
|
## Generating State Machine Diagrams
|
126
159
|
|
@@ -144,7 +177,7 @@ You can specify relative or absolute output path via environment variable `DEST_
|
|
144
177
|
|
145
178
|
## Support Rails Versions
|
146
179
|
|
147
|
-
* Rails 4.1.x, 4.2.x, 5.0,
|
180
|
+
* Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, and 7.1 (edge)
|
148
181
|
|
149
182
|
|
150
183
|
## Contributing
|
data/Rakefile
CHANGED
@@ -13,11 +13,3 @@ Rake::TestTask.new(:test) do |t|
|
|
13
13
|
end
|
14
14
|
|
15
15
|
task default: :test
|
16
|
-
|
17
|
-
namespace :test do
|
18
|
-
task :all do
|
19
|
-
YAML.load(File.read(File.expand_path('.travis.yml')))['gemfile'].each do |gemfile|
|
20
|
-
sh "BUNDLE_GEMFILE='#{gemfile}' bundle exec rake test"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -0,0 +1,14 @@
|
|
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'
|
@@ -5,9 +5,9 @@ require 'rails/generators/named_base'
|
|
5
5
|
module StatefulEnum
|
6
6
|
module Generators
|
7
7
|
class GraphGenerator < ::Rails::Generators::NamedBase
|
8
|
-
desc 'Draws a state machine diagram'
|
8
|
+
desc 'Draws a state machine diagram as a PNG file'
|
9
9
|
def draw
|
10
|
-
require 'graphviz'
|
10
|
+
require 'ruby-graphviz'
|
11
11
|
StatefulEnum::Machine.prepend StatefulEnum::Graph
|
12
12
|
class_name.constantize
|
13
13
|
end
|
@@ -50,6 +50,7 @@ module StatefulEnum
|
|
50
50
|
class EventDrawer < ::StatefulEnum::Machine::Event
|
51
51
|
def initialize(g, states, prefix, suffix, name, &block)
|
52
52
|
@g, @states, @prefix, @suffix, @name = g, states, prefix, suffix, name
|
53
|
+
@before, @after = [], []
|
53
54
|
|
54
55
|
instance_eval(&block) if block
|
55
56
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/named_base'
|
4
|
+
|
5
|
+
module StatefulEnum
|
6
|
+
module Generators
|
7
|
+
class PlantumlGenerator < ::Rails::Generators::NamedBase
|
8
|
+
desc 'Draws a PlantUML state machine diagram'
|
9
|
+
def plantuml
|
10
|
+
StatefulEnum::Machine.prepend StatefulEnum::PlantUML
|
11
|
+
class_name.constantize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module PlantUML
|
17
|
+
def initialize(model, column, states, prefix, suffix, &block)
|
18
|
+
super
|
19
|
+
UmlWriter.new model, column, states, @prefix, @suffix, &block
|
20
|
+
end
|
21
|
+
|
22
|
+
class UmlWriter
|
23
|
+
def initialize(model, column, states, prefix, suffix, &block)
|
24
|
+
@states, @prefix, @suffix = states, prefix, suffix
|
25
|
+
@items = []
|
26
|
+
|
27
|
+
if (default_value = model.columns_hash[column.to_s].default)
|
28
|
+
default_label = model.defined_enums[column.to_s].key default_value.to_i # SQLite returns the default value in String
|
29
|
+
end
|
30
|
+
|
31
|
+
instance_eval(&block)
|
32
|
+
|
33
|
+
lines = default_label ? ["[*] --> #{default_label}"] : []
|
34
|
+
lines.concat @items.map {|item| "#{item.from} --> #{item.to} :#{item.label}" }
|
35
|
+
(@items.map(&:to).uniq - @items.map(&:from).uniq).each do |final|
|
36
|
+
lines.push "#{final} --> [*]"
|
37
|
+
end
|
38
|
+
|
39
|
+
File.write(File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}.puml"), lines.join("\n") << "\n")
|
40
|
+
end
|
41
|
+
|
42
|
+
def event(name, &block)
|
43
|
+
EventStore.new @items, @states, @prefix, @suffix, name, &block
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class EventStore < ::StatefulEnum::Machine::Event
|
48
|
+
def initialize(items, states, prefix, suffix, name, &block)
|
49
|
+
@items, @states, @prefix, @suffix, @name, @before, @after = items, states, prefix, suffix, name, [], []
|
50
|
+
|
51
|
+
instance_eval(&block) if block
|
52
|
+
end
|
53
|
+
|
54
|
+
def transition(transitions, options = {})
|
55
|
+
if options.blank?
|
56
|
+
transitions.delete :if
|
57
|
+
transitions.delete :unless
|
58
|
+
end
|
59
|
+
|
60
|
+
transitions.each_pair do |from, to|
|
61
|
+
Array(from).each do |f|
|
62
|
+
@items.push Item.new(f, to, "#{@prefix}#{@name}#{@suffix}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Item = Struct.new(:from, :to, :label)
|
69
|
+
end
|
70
|
+
end
|
@@ -9,14 +9,32 @@ module StatefulEnum
|
|
9
9
|
# transition :unassigned => :assigned
|
10
10
|
# end
|
11
11
|
# end
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if Rails::VERSION::MAJOR >= 7
|
13
|
+
def enum(name = nil, values = nil, **options, &block)
|
14
|
+
return super unless block
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
StatefulEnum::Machine.new
|
16
|
+
definitions = super name, values, **options
|
17
|
+
|
18
|
+
if name
|
19
|
+
(@_defined_stateful_enums ||= []) << StatefulEnum::Machine.new(self, name, (definitions.is_a?(Hash) ? definitions.keys : definitions), options[:prefix], options[:suffix], &block)
|
20
|
+
else
|
21
|
+
definitions.each do |column, states|
|
22
|
+
(@_defined_stateful_enums ||= []) << StatefulEnum::Machine.new(self, column, (states.is_a?(Hash) ? states.keys : states), options[:_prefix], options[:_suffix], &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
definitions
|
27
|
+
end
|
28
|
+
else
|
29
|
+
def enum(definitions, &block)
|
30
|
+
return super unless block
|
31
|
+
|
32
|
+
# Preserving prefix and suffix values before calling super because the super destroys the given Hash
|
33
|
+
prefix, suffix = definitions[:_prefix], definitions[:_suffix] if Rails::VERSION::MAJOR >= 5
|
34
|
+
enum_values = super definitions
|
35
|
+
|
36
|
+
enum_values.each_pair do |column, states|
|
37
|
+
(@_defined_stateful_enums ||= []) << StatefulEnum::Machine.new(self, column, (states.is_a?(Hash) ? states.keys : states), prefix, suffix, &block)
|
20
38
|
end
|
21
39
|
end
|
22
40
|
end
|
@@ -2,18 +2,16 @@
|
|
2
2
|
|
3
3
|
module StatefulEnum
|
4
4
|
class Machine
|
5
|
+
attr_reader :events
|
6
|
+
|
5
7
|
def initialize(model, column, states, prefix, suffix, &block)
|
6
|
-
@model, @column, @states, @
|
7
|
-
@prefix = if prefix
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"_#{column}"
|
14
|
-
elsif suffix
|
15
|
-
"_#{suffix}"
|
16
|
-
end
|
8
|
+
@model, @column, @states, @events = model, column, states.map(&:to_sym), []
|
9
|
+
@prefix = if prefix
|
10
|
+
prefix == true ? "#{column}_" : "#{prefix}_"
|
11
|
+
end
|
12
|
+
@suffix = if suffix
|
13
|
+
suffix == true ? "_#{column}" : "_#{suffix}"
|
14
|
+
end
|
17
15
|
|
18
16
|
# undef non-verb methods e.g. Model#active!
|
19
17
|
states.each do |state|
|
@@ -24,54 +22,67 @@ module StatefulEnum
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def event(name, &block)
|
27
|
-
raise ArgumentError, "event: :#{name} has already been defined." if @
|
28
|
-
Event.new
|
29
|
-
@event_names << name
|
25
|
+
raise ArgumentError, "event: :#{name} has already been defined." if @events.map(&:name).include? name
|
26
|
+
@events << Event.new(@model, @column, @states, @prefix, @suffix, name, &block)
|
30
27
|
end
|
31
28
|
|
32
29
|
class Event
|
30
|
+
attr_reader :name, :value_method_name, :transitions
|
31
|
+
|
33
32
|
def initialize(model, column, states, prefix, suffix, name, &block)
|
34
|
-
@states, @name, @transitions, @before, @after = states, name, {},
|
33
|
+
@states, @name, @transitions, @before, @after = states, name, {}, [], []
|
35
34
|
|
36
35
|
instance_eval(&block) if block
|
37
36
|
|
38
37
|
transitions, before, after = @transitions, @before, @after
|
39
|
-
|
38
|
+
@value_method_name = value_method_name = :"#{prefix}#{name}#{suffix}"
|
40
39
|
|
41
40
|
# defining event methods
|
42
41
|
model.class_eval do
|
43
42
|
# def assign()
|
44
|
-
detect_enum_conflict! column,
|
45
|
-
|
43
|
+
detect_enum_conflict! column, value_method_name
|
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
|
46
55
|
to, condition = transitions[send(column).to_sym]
|
47
56
|
#TODO better error
|
48
|
-
if to && (
|
57
|
+
if to && (condition.nil? || instance_exec(&condition))
|
49
58
|
#TODO transaction?
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
ret
|
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
|
62
|
+
end
|
55
63
|
else
|
56
64
|
false
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
68
|
# def assign!()
|
61
|
-
detect_enum_conflict! column, "#{
|
62
|
-
define_method "#{
|
63
|
-
send(
|
69
|
+
detect_enum_conflict! column, "#{value_method_name}!"
|
70
|
+
define_method "#{value_method_name}!" do
|
71
|
+
send(value_method_name) || raise('Invalid transition')
|
64
72
|
end
|
65
73
|
|
66
74
|
# def can_assign?()
|
67
|
-
detect_enum_conflict! column, "can_#{
|
68
|
-
define_method "can_#{
|
69
|
-
|
75
|
+
detect_enum_conflict! column, "can_#{value_method_name}?"
|
76
|
+
define_method "can_#{value_method_name}?" do
|
77
|
+
state = send(column).to_sym
|
78
|
+
return false unless transitions.key? state
|
79
|
+
_to, condition = transitions[state]
|
80
|
+
condition.nil? || instance_exec(&condition)
|
70
81
|
end
|
71
82
|
|
72
83
|
# def assign_transition()
|
73
|
-
detect_enum_conflict! column, "#{
|
74
|
-
define_method "#{
|
84
|
+
detect_enum_conflict! column, "#{value_method_name}_transition"
|
85
|
+
define_method "#{value_method_name}_transition" do
|
75
86
|
transitions[send(column).to_sym].try! :first
|
76
87
|
end
|
77
88
|
end
|
@@ -100,11 +111,11 @@ module StatefulEnum
|
|
100
111
|
end
|
101
112
|
|
102
113
|
def before(&block)
|
103
|
-
@before
|
114
|
+
@before << block
|
104
115
|
end
|
105
116
|
|
106
117
|
def after(&block)
|
107
|
-
@after
|
118
|
+
@after << block
|
108
119
|
end
|
109
120
|
end
|
110
121
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'stateful_enum/active_record_extension'
|
4
|
+
require 'stateful_enum/state_inspection'
|
4
5
|
|
5
6
|
module StatefulEnum
|
6
7
|
class Railtie < ::Rails::Railtie
|
7
|
-
|
8
|
-
|
8
|
+
initializer 'stateful_enum' do
|
9
|
+
ActiveSupport.on_load :active_record do
|
10
|
+
::ActiveRecord::Base.extend StatefulEnum::ActiveRecordEnumExtension
|
11
|
+
::ActiveRecord::Base.include StatefulEnum::StateInspection
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stateful_enum/machine'
|
4
|
+
|
5
|
+
module StatefulEnum
|
6
|
+
module StateInspection
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def stateful_enum
|
11
|
+
@_defined_stateful_enums
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def stateful_enum
|
16
|
+
StateInspector.new(self.class.stateful_enum, self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class StateInspector
|
21
|
+
def initialize(defined_stateful_enums, model_instance)
|
22
|
+
@defined_stateful_enums, @model_instance = defined_stateful_enums, model_instance
|
23
|
+
end
|
24
|
+
|
25
|
+
# List of possible events from the current state
|
26
|
+
def possible_events
|
27
|
+
@defined_stateful_enums.flat_map {|se| se.events.select {|e| @model_instance.send("can_#{e.value_method_name}?") } }
|
28
|
+
end
|
29
|
+
|
30
|
+
# List of possible event names from the current state
|
31
|
+
def possible_event_names
|
32
|
+
possible_events.map(&:value_method_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
# List of transitionable states from the current state
|
36
|
+
def possible_states
|
37
|
+
@defined_stateful_enums.flat_map do |stateful_enum|
|
38
|
+
col = stateful_enum.instance_variable_get :@column
|
39
|
+
pe = stateful_enum.events.select {|e| @model_instance.send("can_#{e.value_method_name}?") }
|
40
|
+
pe.flat_map {|e| e.transitions[@model_instance.send(col).to_sym].first }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stateful_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,8 +101,8 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/workflows/main.yml"
|
104
105
|
- ".gitignore"
|
105
|
-
- ".travis.yml"
|
106
106
|
- Gemfile
|
107
107
|
- MIT-LICENSE
|
108
108
|
- README.md
|
@@ -111,19 +111,27 @@ files:
|
|
111
111
|
- bin/setup
|
112
112
|
- gemfiles/Gemfile-rails.4.1.x
|
113
113
|
- gemfiles/Gemfile-rails.4.2.x
|
114
|
-
- gemfiles/Gemfile-rails.5.0.
|
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
|
115
121
|
- lib/generators/stateful_enum/graph_generator.rb
|
122
|
+
- lib/generators/stateful_enum/plantuml_generator.rb
|
116
123
|
- lib/stateful_enum.rb
|
117
124
|
- lib/stateful_enum/active_record_extension.rb
|
118
125
|
- lib/stateful_enum/machine.rb
|
119
126
|
- lib/stateful_enum/railtie.rb
|
127
|
+
- lib/stateful_enum/state_inspection.rb
|
120
128
|
- lib/stateful_enum/version.rb
|
121
129
|
- stateful_enum.gemspec
|
122
130
|
homepage: https://github.com/amatsuda/stateful_enum
|
123
131
|
licenses:
|
124
132
|
- MIT
|
125
133
|
metadata: {}
|
126
|
-
post_install_message:
|
134
|
+
post_install_message:
|
127
135
|
rdoc_options: []
|
128
136
|
require_paths:
|
129
137
|
- lib
|
@@ -138,9 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
146
|
- !ruby/object:Gem::Version
|
139
147
|
version: '0'
|
140
148
|
requirements: []
|
141
|
-
|
142
|
-
|
143
|
-
signing_key:
|
149
|
+
rubygems_version: 3.1.6
|
150
|
+
signing_key:
|
144
151
|
specification_version: 4
|
145
152
|
summary: A state machine plugin on top of ActiveRecord::Enum
|
146
153
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
cache:
|
6
|
-
- apt
|
7
|
-
- bundler
|
8
|
-
|
9
|
-
rvm:
|
10
|
-
- 2.2.5
|
11
|
-
- 2.3.1
|
12
|
-
- ruby-head
|
13
|
-
|
14
|
-
matrix:
|
15
|
-
exclude:
|
16
|
-
- rvm: ruby-head
|
17
|
-
gemfile: gemfiles/Gemfile-rails.4.1.x
|
18
|
-
- rvm: ruby-head
|
19
|
-
gemfile: gemfiles/Gemfile-rails.4.2.x
|
20
|
-
|
21
|
-
gemfile:
|
22
|
-
- gemfiles/Gemfile-rails.4.1.x
|
23
|
-
- gemfiles/Gemfile-rails.4.2.x
|
24
|
-
- gemfiles/Gemfile-rails.5.0.0
|
25
|
-
|
26
|
-
addons:
|
27
|
-
apt:
|
28
|
-
packages:
|
29
|
-
- graphviz
|
30
|
-
|
31
|
-
matrix:
|
32
|
-
allow_failures:
|
33
|
-
- rvm: ruby-head
|