stateful_enum 0.3.1 → 0.4.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
  SHA1:
3
- metadata.gz: c1f17ddca9a9a86a18e5a6dcfcc448a0511e7f63
4
- data.tar.gz: c3fda258904629bd7be634a2cb8986c4c97f4d86
3
+ metadata.gz: 3c76765e33135bb963a09c10f7b35c0f64c623a4
4
+ data.tar.gz: 13c55c02af388232d71cfa9341f4d226b66c39fe
5
5
  SHA512:
6
- metadata.gz: bf2a2a383dcbc193fb4c2ff91b09c85d21ba39c7e13c60abdf1e8ada96b2adb76d180dd125581315b50ece0459272a38e59df0ecad05c489c485e56acf511366
7
- data.tar.gz: dc97471c1c8455531706b98e89c69e6158abe215ba631694ab2dfd4216f70697e593adbbe1316f486e3b126c2370da6d9f167825eb47d06910856d9052a5aabe
6
+ metadata.gz: c20bf58167c940d157fb73821d81a0e08daf080642b78f69181e7237a49408e1d819035d6618cae86b15acfb380f3aa3b37de12f10dc5cfd53e831ad0f63ac5c
7
+ data.tar.gz: 86d6d5a1e299d3721319b4dcb51f43031feb1cc0b44f5ec95f91dcf1fe2461d011e54897f8fa90aebef0d090c168424d86c46ed3453df4ec5d5ae93ac99893fe
@@ -7,17 +7,11 @@ cache:
7
7
  - bundler
8
8
 
9
9
  rvm:
10
- - 2.2.5
11
- - 2.3.1
10
+ - 2.2.6
11
+ - 2.3.3
12
+ - 2.4.0
12
13
  - ruby-head
13
14
 
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
15
  gemfile:
22
16
  - gemfiles/Gemfile-rails.4.1.x
23
17
  - gemfiles/Gemfile-rails.4.2.x
@@ -29,5 +23,14 @@ addons:
29
23
  - graphviz
30
24
 
31
25
  matrix:
26
+ exclude:
27
+ - rvm: 2.4.0
28
+ gemfile: gemfiles/Gemfile-rails.4.1.x
29
+ - rvm: 2.4.0
30
+ gemfile: gemfiles/Gemfile-rails.4.2.x
31
+ - rvm: ruby-head
32
+ gemfile: gemfiles/Gemfile-rails.4.1.x
33
+ - rvm: ruby-head
34
+ gemfile: gemfiles/Gemfile-rails.4.2.x
32
35
  allow_failures:
33
36
  - rvm: ruby-head
@@ -5,7 +5,7 @@ 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
10
  require 'graphviz'
11
11
  StatefulEnum::Machine.prepend StatefulEnum::Graph
@@ -0,0 +1,71 @@
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 = 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
+ class Item < Struct.new(:from, :to, :label)
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StatefulEnum
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.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.3.1
4
+ version: 0.4.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: 2016-08-14 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,6 +113,7 @@ files:
113
113
  - gemfiles/Gemfile-rails.4.2.x
114
114
  - gemfiles/Gemfile-rails.5.0.0
115
115
  - lib/generators/stateful_enum/graph_generator.rb
116
+ - lib/generators/stateful_enum/plantuml_generator.rb
116
117
  - lib/stateful_enum.rb
117
118
  - lib/stateful_enum/active_record_extension.rb
118
119
  - lib/stateful_enum/machine.rb
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  requirements: []
141
142
  rubyforge_project:
142
- rubygems_version: 2.5.1
143
+ rubygems_version: 2.6.8
143
144
  signing_key:
144
145
  specification_version: 4
145
146
  summary: A state machine plugin on top of ActiveRecord::Enum