stateful_enum 0.6.0 → 0.7.0

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: 6d0d82f2cf13496a059030aac0a34a998e47997bcbf6605637fa488c5363454d
4
- data.tar.gz: 69fc206ccfc3d4290ad0961cac0d011e92ed1fa5421c0064bd881213d52082d5
3
+ metadata.gz: 78d2de46a67e071c7ec7d4b0147d6a52768af7fef8ba81a7454c1f129dcd6b0d
4
+ data.tar.gz: 38ddee71fcc5406f6fa8ac93ae582230277173527a5ab32fc8e36a7f9aa15f10
5
5
  SHA512:
6
- metadata.gz: e3f5cec3415b7401c36acf28d5dda810d75818cc88b38a768e721757aaf508714ee0613b7926bb0b5e05832df83e6d7deadc3cc0b816eb3e7ab9a6286f6b1399
7
- data.tar.gz: 6a8d8196552d59c696c42872ae3a9decb62ddef4e75b42566af8e45cd2d3887e3fe6688808ac230f3d35ba7501f4e06328a4fad93462d3e8aee4fca985da4720
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://travis-ci.org/amatsuda/stateful_enum.svg?branch=master)](https://travis-ci.org/amatsuda/stateful_enum)
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
 
@@ -177,7 +177,7 @@ You can specify relative or absolute output path via environment variable `DEST_
177
177
 
178
178
  ## Support Rails Versions
179
179
 
180
- * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, and 6.0 (edge)
180
+ * Rails 4.1.x, 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, and 7.1 (edge)
181
181
 
182
182
 
183
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
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', '~> 5.2.0'
5
+ gem 'rails', git: 'https://github.com/rails/rails/', branch: '5-2-stable'
6
6
  gem 'sqlite3', '~> 1.3.6'
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', '~> 6.0.0.rc1'
6
- gem 'selenium-webdriver'
5
+ gem 'rails', '~> 6.0.0'
6
+ gem 'sqlite3', '~> 1.4'
@@ -0,0 +1,7 @@
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'
@@ -0,0 +1,7 @@
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'
@@ -9,13 +9,31 @@ module StatefulEnum
9
9
  # transition :unassigned => :assigned
10
10
  # end
11
11
  # end
12
- def enum(definitions, &block)
13
- prefix, suffix = definitions[:_prefix], definitions[:_suffix] if Rails::VERSION::MAJOR >= 5
14
- enum = super definitions
12
+ if Rails::VERSION::MAJOR >= 7
13
+ def enum(name = nil, values = nil, **options, &block)
14
+ return super unless block
15
15
 
16
- if block
17
- definitions.each_key do |column|
18
- states = enum[column]
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|
19
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
@@ -5,7 +5,7 @@ module StatefulEnum
5
5
  attr_reader :events
6
6
 
7
7
  def initialize(model, column, states, prefix, suffix, &block)
8
- @model, @column, @states, @events = model, column, states, []
8
+ @model, @column, @states, @events = model, column, states.map(&:to_sym), []
9
9
  @prefix = if prefix
10
10
  prefix == true ? "#{column}_" : "#{prefix}_"
11
11
  end
@@ -27,7 +27,7 @@ module StatefulEnum
27
27
  end
28
28
 
29
29
  class Event
30
- attr_reader :name, :value_method_name
30
+ attr_reader :name, :value_method_name, :transitions
31
31
 
32
32
  def initialize(model, column, states, prefix, suffix, name, &block)
33
33
  @states, @name, @transitions, @before, @after = states, name, {}, [], []
@@ -54,7 +54,7 @@ module StatefulEnum
54
54
  define_method value_method_name do
55
55
  to, condition = transitions[send(column).to_sym]
56
56
  #TODO better error
57
- if to && (!condition || instance_exec(&condition))
57
+ if to && (condition.nil? || instance_exec(&condition))
58
58
  #TODO transaction?
59
59
  run_callbacks value_method_name do
60
60
  original_method = self.class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
@@ -77,7 +77,7 @@ module StatefulEnum
77
77
  state = send(column).to_sym
78
78
  return false unless transitions.key? state
79
79
  _to, condition = transitions[state]
80
- !condition || instance_exec(&condition)
80
+ condition.nil? || instance_exec(&condition)
81
81
  end
82
82
 
83
83
  # def assign_transition()
@@ -37,7 +37,7 @@ module StatefulEnum
37
37
  @defined_stateful_enums.flat_map do |stateful_enum|
38
38
  col = stateful_enum.instance_variable_get :@column
39
39
  pe = stateful_enum.events.select {|e| @model_instance.send("can_#{e.value_method_name}?") }
40
- pe.flat_map {|e| e.instance_variable_get(:@transitions)[@model_instance.send(col).to_sym].first }
40
+ pe.flat_map {|e| e.transitions[@model_instance.send(col).to_sym].first }
41
41
  end
42
42
  end
43
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StatefulEnum
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  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.6.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: 2019-06-06 00:00:00.000000000 Z
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
@@ -115,6 +115,8 @@ files:
115
115
  - gemfiles/Gemfile-rails.5.1.x
116
116
  - gemfiles/Gemfile-rails.5.2.x
117
117
  - gemfiles/Gemfile-rails.6.0.x
118
+ - gemfiles/Gemfile-rails.6.1.x
119
+ - gemfiles/Gemfile-rails.7.0.x
118
120
  - gemfiles/Gemfile-rails.edge
119
121
  - lib/generators/stateful_enum/graph_generator.rb
120
122
  - lib/generators/stateful_enum/plantuml_generator.rb
@@ -129,7 +131,7 @@ homepage: https://github.com/amatsuda/stateful_enum
129
131
  licenses:
130
132
  - MIT
131
133
  metadata: {}
132
- post_install_message:
134
+ post_install_message:
133
135
  rdoc_options: []
134
136
  require_paths:
135
137
  - lib
@@ -144,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
146
  - !ruby/object:Gem::Version
145
147
  version: '0'
146
148
  requirements: []
147
- rubygems_version: 3.0.3
148
- signing_key:
149
+ rubygems_version: 3.1.6
150
+ signing_key:
149
151
  specification_version: 4
150
152
  summary: A state machine plugin on top of ActiveRecord::Enum
151
153
  test_files: []
data/.travis.yml DELETED
@@ -1,47 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- cache:
6
- - apt
7
- - bundler
8
- before_install:
9
- - gem i bundler -v '<2'
10
-
11
- addons:
12
- apt:
13
- packages:
14
- - graphviz
15
-
16
- matrix:
17
- include:
18
- - rvm: 2.6.0
19
- gemfile: gemfiles/Gemfile-rails.6.0.x
20
-
21
- - rvm: 2.6.0
22
- gemfile: gemfiles/Gemfile-rails.5.2.x
23
- - rvm: 2.6.0
24
- gemfile: gemfiles/Gemfile-rails.5.1.x
25
- - rvm: 2.6.0
26
- gemfile: gemfiles/Gemfile-rails.5.0.x
27
-
28
- - rvm: 2.5.3
29
- gemfile: gemfiles/Gemfile-rails.4.2.x
30
-
31
- - rvm: 2.3.8
32
- gemfile: gemfiles/Gemfile-rails.4.1.x
33
-
34
- - rvm: 2.4.5
35
- gemfile: gemfiles/Gemfile-rails.5.2.x
36
- - rvm: 2.2.10
37
- gemfile: gemfiles/Gemfile-rails.5.2.x
38
-
39
- - rvm: ruby-head
40
- gemfile: gemfiles/Gemfile-rails.5.2.x
41
-
42
- - rvm: 2.6.0
43
- gemfile: gemfiles/Gemfile-rails.edge
44
-
45
- allow_failures:
46
- - rvm: ruby-head
47
- - gemfile: gemfiles/Gemfile-rails.edge