stateful_enum 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: a1388d189d8fe2a3c7f30a3b765526823295ef8a
4
- data.tar.gz: c672208f53cdd2b07ec8c7e3d03f9c284e915d62
3
+ metadata.gz: c1f17ddca9a9a86a18e5a6dcfcc448a0511e7f63
4
+ data.tar.gz: c3fda258904629bd7be634a2cb8986c4c97f4d86
5
5
  SHA512:
6
- metadata.gz: 6110d07106f0590e8651bc0c1b91f5e7e72d1ba30063ddb67a2a151405cc2b3c9aaa08153516b8115fbc7e82e59a20a140cb3a112307295246a08aea43f1238f
7
- data.tar.gz: af06537cecafe02ce03d1744f202ece3d3039be662f5d7a726277350d64e51ca41b5d907b13c01da43b3d52e2fc71eba91b02420b6eaf7d16544f1d00b08fdfe
6
+ metadata.gz: bf2a2a383dcbc193fb4c2ff91b09c85d21ba39c7e13c60abdf1e8ada96b2adb76d180dd125581315b50ece0459272a38e59df0ecad05c489c485e56acf511366
7
+ data.tar.gz: dc97471c1c8455531706b98e89c69e6158abe215ba631694ab2dfd4216f70697e593adbbe1316f486e3b126c2370da6d9f167825eb47d06910856d9052a5aabe
data/.travis.yml CHANGED
@@ -1,21 +1,32 @@
1
1
  language: ruby
2
2
 
3
+ sudo: false
4
+
3
5
  cache:
6
+ - apt
4
7
  - bundler
5
8
 
6
9
  rvm:
7
- - 2.2.4
8
- - 2.3.0
10
+ - 2.2.5
11
+ - 2.3.1
9
12
  - ruby-head
10
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
+
11
21
  gemfile:
12
22
  - gemfiles/Gemfile-rails.4.1.x
13
23
  - gemfiles/Gemfile-rails.4.2.x
14
- - gemfiles/Gemfile-rails.5.0.0.beta3
24
+ - gemfiles/Gemfile-rails.5.0.0
15
25
 
16
- before_install:
17
- - sudo apt-get install graphviz
18
- - gem install bundler -v 1.11.2
26
+ addons:
27
+ apt:
28
+ packages:
29
+ - graphviz
19
30
 
20
31
  matrix:
21
32
  allow_failures:
data/README.md CHANGED
@@ -131,11 +131,22 @@ Note that you need to bundle the ruby-graphviz gem (and its dependencies) for th
131
131
  % rails g stateful_enum:graph bug
132
132
  ```
133
133
 
134
+ You can specify relative or absolute output path via environment variable `DEST_DIR`.
135
+
136
+ ```bash
137
+ % DEST_DIR=doc rails g stateful_enum:graph bug
138
+ ```
139
+
134
140
  ## TODO
135
141
 
136
142
  * Better Error handling
137
143
 
138
144
 
145
+ ## Support Rails Versions
146
+
147
+ * Rails 4.1.x, 4.2.x, 5.0, and 5.1 (edge)
148
+
149
+
139
150
  ## Contributing
140
151
 
141
152
  Pull requests are welcome on GitHub at https://github.com/amatsuda/stateful_enum.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
  require 'yaml'
@@ -6,6 +8,8 @@ Rake::TestTask.new(:test) do |t|
6
8
  t.libs << "test"
7
9
  t.libs << "lib"
8
10
  t.test_files = FileList['test/**/*_test.rb']
11
+ t.warning = true
12
+ t.verbose = true
9
13
  end
10
14
 
11
15
  task default: :test
@@ -4,5 +4,5 @@ gem 'stateful_enum', path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
6
  gem 'sqlite3'
7
- gem 'minitest', '~> 5.0'
7
+ gem 'test-unit-rails'
8
8
  gem 'ruby-graphviz'
@@ -4,5 +4,5 @@ gem 'stateful_enum', path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
6
  gem 'sqlite3'
7
- gem 'minitest', '~> 5.0'
7
+ gem 'test-unit-rails'
8
8
  gem 'ruby-graphviz'
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'stateful_enum', path: '..'
4
4
 
5
- gem 'rails', '~> 5.0.0.beta3'
5
+ gem 'rails', '~> 5.0.0'
6
6
  gem 'sqlite3'
7
- gem 'minitest', '~> 5.0'
7
+ gem 'test-unit-rails'
8
8
  gem 'ruby-graphviz'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/named_base'
2
4
 
3
5
  module StatefulEnum
@@ -13,28 +15,31 @@ module StatefulEnum
13
15
  end
14
16
 
15
17
  module Graph
16
- def initialize(model, _column, states, prefix, suffix, &block)
18
+ def initialize(model, column, states, prefix, suffix, &block)
17
19
  super
18
- GraphDrawer.new model, states, @prefix, @suffix, &block if block
20
+ GraphDrawer.new model, column, states, @prefix, @suffix, &block
19
21
  end
20
22
 
21
23
  class GraphDrawer
22
- def initialize(model, states, prefix, suffix, &block)
24
+ def initialize(model, column, states, prefix, suffix, &block)
23
25
  @states, @prefix, @suffix = states, prefix, suffix
24
26
  @g = ::GraphViz.new 'G', rankdir: 'TB'
25
27
 
26
28
  states.each do |state|
27
29
  @g.add_node state.to_s, label: state.to_s, width: '1', height: '1', shape: 'ellipse'
28
30
  end
29
- @g.add_edge @g.add_node('start state', shape: 'point'), @g.get_node_at_index(0)
31
+ if (default_value = model.columns_hash[column.to_s].default)
32
+ default_label = model.defined_enums[column.to_s].key default_value.to_i # SQLite returns the default value in String
33
+ @g.add_edge @g.add_node('start state', shape: 'point'), @g.get_node(default_label)
34
+ end
30
35
 
31
36
  instance_eval(&block)
32
37
 
33
- (@g.each_edge.map {|e| e.node_two }.uniq - @g.each_edge.map {|e| e.node_one }.uniq).each do |final|
38
+ (@g.each_edge.map(&:node_two).uniq - @g.each_edge.map(&:node_one).uniq).each do |final|
34
39
  @g.get_node(final) {|n| n['shape'] = 'doublecircle' }
35
40
  end
36
41
 
37
- @g.output png: "#{model.name}.png"
42
+ @g.output png: File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}.png")
38
43
  end
39
44
 
40
45
  def event(name, &block)
data/lib/stateful_enum.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stateful_enum/version'
2
4
  require 'stateful_enum/railtie'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stateful_enum/machine'
2
4
 
3
5
  module StatefulEnum
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StatefulEnum
2
4
  class Machine
3
5
  def initialize(model, column, states, prefix, suffix, &block)
@@ -41,7 +43,7 @@ module StatefulEnum
41
43
  # def assign()
42
44
  detect_enum_conflict! column, new_method_name
43
45
  define_method new_method_name do
44
- to, condition = transitions[self.send(column).to_sym]
46
+ to, condition = transitions[send(column).to_sym]
45
47
  #TODO better error
46
48
  if to && (!condition || instance_exec(&condition))
47
49
  #TODO transaction?
@@ -64,13 +66,13 @@ module StatefulEnum
64
66
  # def can_assign?()
65
67
  detect_enum_conflict! column, "can_#{new_method_name}?"
66
68
  define_method "can_#{new_method_name}?" do
67
- transitions.has_key? self.send(column).to_sym
69
+ transitions.key? send(column).to_sym
68
70
  end
69
71
 
70
72
  # def assign_transition()
71
73
  detect_enum_conflict! column, "#{new_method_name}_transition"
72
74
  define_method "#{new_method_name}_transition" do
73
- transitions[self.send(column).to_sym].try! :first
75
+ transitions[send(column).to_sym].try! :first
74
76
  end
75
77
  end
76
78
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stateful_enum/active_record_extension'
2
4
 
3
5
  module StatefulEnum
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StatefulEnum
2
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
3
5
  end
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.11"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "minitest", "~> 5.0"
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'test-unit-rails'
25
25
  spec.add_development_dependency 'rails'
26
26
  spec.add_development_dependency 'sqlite3'
27
+ spec.add_development_dependency 'ruby-graphviz'
27
28
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateful_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-28 00:00:00.000000000 Z
11
+ date: 2016-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: test-unit-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-graphviz
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: A state machine plugin on top of ActiveRecord::Enum
84
98
  email:
85
99
  - ronnie@dio.jp
@@ -97,7 +111,7 @@ files:
97
111
  - bin/setup
98
112
  - gemfiles/Gemfile-rails.4.1.x
99
113
  - gemfiles/Gemfile-rails.4.2.x
100
- - gemfiles/Gemfile-rails.5.0.0.beta3
114
+ - gemfiles/Gemfile-rails.5.0.0
101
115
  - lib/generators/stateful_enum/graph_generator.rb
102
116
  - lib/stateful_enum.rb
103
117
  - lib/stateful_enum/active_record_extension.rb
@@ -125,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
139
  version: '0'
126
140
  requirements: []
127
141
  rubyforge_project:
128
- rubygems_version: 2.6.1
142
+ rubygems_version: 2.5.1
129
143
  signing_key:
130
144
  specification_version: 4
131
145
  summary: A state machine plugin on top of ActiveRecord::Enum