stateful_enum 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +25 -17
- data/README.md +2 -1
- 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.edge +14 -0
- data/lib/generators/stateful_enum/graph_generator.rb +2 -1
- data/lib/generators/stateful_enum/plantuml_generator.rb +1 -1
- data/lib/stateful_enum/machine.rb +27 -19
- data/lib/stateful_enum/version.rb +1 -1
- metadata +7 -4
- 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: fdcc7c193f8597cec775968ecf6cfae38dfe09299d024b877b5da5fae7e5e5ca
|
4
|
+
data.tar.gz: 20558b138fd9df10e915e40ce6ff197b436a3fe4ce4717f935207dae21d7254e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f89d7a82fc8264fbd93b3bd85bb320607409fa662f7726f5b79f04b65da88ee3f080ff39a9ba8d5a2a14c128a1b52fdbf7c773ac6f9cbad8df61cff7052a9e8
|
7
|
+
data.tar.gz: b2bb43940cffd1be568fff1903920f569585fc3e56a257b9f9d824427ec42de5b2aeaf675faeab48404794ea8179d671dc2a661b98f379e5a7f3f679d6900121
|
data/.travis.yml
CHANGED
@@ -5,17 +5,8 @@ sudo: false
|
|
5
5
|
cache:
|
6
6
|
- apt
|
7
7
|
- bundler
|
8
|
-
|
9
|
-
|
10
|
-
- 2.2.6
|
11
|
-
- 2.3.3
|
12
|
-
- 2.4.0
|
13
|
-
- ruby-head
|
14
|
-
|
15
|
-
gemfile:
|
16
|
-
- gemfiles/Gemfile-rails.4.1.x
|
17
|
-
- gemfiles/Gemfile-rails.4.2.x
|
18
|
-
- gemfiles/Gemfile-rails.5.0.0
|
8
|
+
before_install:
|
9
|
+
- gem i bundler -v '<2'
|
19
10
|
|
20
11
|
addons:
|
21
12
|
apt:
|
@@ -23,14 +14,31 @@ addons:
|
|
23
14
|
- graphviz
|
24
15
|
|
25
16
|
matrix:
|
26
|
-
|
27
|
-
- rvm: 2.
|
28
|
-
gemfile: gemfiles/Gemfile-rails.
|
29
|
-
- rvm: 2.
|
17
|
+
include:
|
18
|
+
- rvm: 2.6.0
|
19
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
20
|
+
- rvm: 2.6.0
|
21
|
+
gemfile: gemfiles/Gemfile-rails.5.1.x
|
22
|
+
- rvm: 2.6.0
|
23
|
+
gemfile: gemfiles/Gemfile-rails.5.0.x
|
24
|
+
|
25
|
+
- rvm: 2.5.3
|
30
26
|
gemfile: gemfiles/Gemfile-rails.4.2.x
|
31
|
-
|
27
|
+
|
28
|
+
- rvm: 2.3.8
|
32
29
|
gemfile: gemfiles/Gemfile-rails.4.1.x
|
30
|
+
|
31
|
+
- rvm: 2.4.5
|
32
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
33
|
+
- rvm: 2.2.10
|
34
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
35
|
+
|
33
36
|
- rvm: ruby-head
|
34
|
-
gemfile: gemfiles/Gemfile-rails.
|
37
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
38
|
+
|
39
|
+
- rvm: 2.6.0
|
40
|
+
gemfile: gemfiles/Gemfile-rails.edge
|
41
|
+
|
35
42
|
allow_failures:
|
36
43
|
- rvm: ruby-head
|
44
|
+
- gemfile: gemfiles/Gemfile-rails.edge
|
data/README.md
CHANGED
@@ -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
|
|
@@ -144,7 +145,7 @@ You can specify relative or absolute output path via environment variable `DEST_
|
|
144
145
|
|
145
146
|
## Support Rails Versions
|
146
147
|
|
147
|
-
* Rails 4.1.x, 4.2.x, 5.0,
|
148
|
+
* Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, and 6.0 (edge)
|
148
149
|
|
149
150
|
|
150
151
|
## Contributing
|
@@ -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'
|
@@ -7,7 +7,7 @@ module StatefulEnum
|
|
7
7
|
class GraphGenerator < ::Rails::Generators::NamedBase
|
8
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
|
@@ -46,7 +46,7 @@ module StatefulEnum
|
|
46
46
|
|
47
47
|
class EventStore < ::StatefulEnum::Machine::Event
|
48
48
|
def initialize(items, states, prefix, suffix, name, &block)
|
49
|
-
@items, @states, @prefix, @suffix, @name = items, states, prefix, suffix, name
|
49
|
+
@items, @states, @prefix, @suffix, @name, @before, @after = items, states, prefix, suffix, name, [], []
|
50
50
|
|
51
51
|
instance_eval(&block) if block
|
52
52
|
end
|
@@ -4,16 +4,12 @@ module StatefulEnum
|
|
4
4
|
class Machine
|
5
5
|
def initialize(model, column, states, prefix, suffix, &block)
|
6
6
|
@model, @column, @states, @event_names = model, column, states, []
|
7
|
-
@prefix = if prefix
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"_#{column}"
|
14
|
-
elsif suffix
|
15
|
-
"_#{suffix}"
|
16
|
-
end
|
7
|
+
@prefix = if prefix
|
8
|
+
prefix == true ? "#{column}_" : "#{prefix}_"
|
9
|
+
end
|
10
|
+
@suffix = if suffix
|
11
|
+
suffix == true ? "_#{column}" : "_#{suffix}"
|
12
|
+
end
|
17
13
|
|
18
14
|
# undef non-verb methods e.g. Model#active!
|
19
15
|
states.each do |state|
|
@@ -31,7 +27,7 @@ module StatefulEnum
|
|
31
27
|
|
32
28
|
class Event
|
33
29
|
def initialize(model, column, states, prefix, suffix, name, &block)
|
34
|
-
@states, @name, @transitions, @before, @after = states, name, {},
|
30
|
+
@states, @name, @transitions, @before, @after = states, name, {}, [], []
|
35
31
|
|
36
32
|
instance_eval(&block) if block
|
37
33
|
|
@@ -42,16 +38,25 @@ module StatefulEnum
|
|
42
38
|
model.class_eval do
|
43
39
|
# def assign()
|
44
40
|
detect_enum_conflict! column, new_method_name
|
41
|
+
|
42
|
+
# defining callbacks
|
43
|
+
define_callbacks new_method_name
|
44
|
+
before.each do |before_callback|
|
45
|
+
model.set_callback new_method_name, :before, before_callback
|
46
|
+
end
|
47
|
+
after.each do |after_callback|
|
48
|
+
model.set_callback new_method_name, :after, after_callback
|
49
|
+
end
|
50
|
+
|
45
51
|
define_method new_method_name do
|
46
52
|
to, condition = transitions[send(column).to_sym]
|
47
53
|
#TODO better error
|
48
54
|
if to && (!condition || instance_exec(&condition))
|
49
55
|
#TODO transaction?
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
ret
|
56
|
+
run_callbacks new_method_name do
|
57
|
+
original_method = self.class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
|
58
|
+
original_method.bind(self).call
|
59
|
+
end
|
55
60
|
else
|
56
61
|
false
|
57
62
|
end
|
@@ -66,7 +71,10 @@ module StatefulEnum
|
|
66
71
|
# def can_assign?()
|
67
72
|
detect_enum_conflict! column, "can_#{new_method_name}?"
|
68
73
|
define_method "can_#{new_method_name}?" do
|
69
|
-
|
74
|
+
state = send(column).to_sym
|
75
|
+
return false unless transitions.key? state
|
76
|
+
_to, condition = transitions[state]
|
77
|
+
!condition || instance_exec(&condition)
|
70
78
|
end
|
71
79
|
|
72
80
|
# def assign_transition()
|
@@ -100,11 +108,11 @@ module StatefulEnum
|
|
100
108
|
end
|
101
109
|
|
102
110
|
def before(&block)
|
103
|
-
@before
|
111
|
+
@before << block
|
104
112
|
end
|
105
113
|
|
106
114
|
def after(&block)
|
107
|
-
@after
|
115
|
+
@after << block
|
108
116
|
end
|
109
117
|
end
|
110
118
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,7 +111,10 @@ 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.edge
|
115
118
|
- lib/generators/stateful_enum/graph_generator.rb
|
116
119
|
- lib/generators/stateful_enum/plantuml_generator.rb
|
117
120
|
- lib/stateful_enum.rb
|
@@ -140,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
143
|
version: '0'
|
141
144
|
requirements: []
|
142
145
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.7.8
|
144
147
|
signing_key:
|
145
148
|
specification_version: 4
|
146
149
|
summary: A state machine plugin on top of ActiveRecord::Enum
|