statemachine 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,9 @@
1
1
  = Statemachine Changelog
2
2
 
3
+ == Version 2.2.0
4
+
5
+ * applied dotfile improvements from @wsobel (https://github.com/slagyr/statemachine/pull/12)
6
+
3
7
  == Version 2.1.0
4
8
 
5
9
  * Do not perform transitions if context method returns false | by @zombor (https://github.com/slagyr/statemachine/pull/11)
@@ -39,15 +39,30 @@ module Statemachine
39
39
 
40
40
  def explore_sm
41
41
  @nodes = []
42
- @transitions = []
43
- @sm.states.values.each { |state|
44
- state.transitions.values.each { |transition|
45
- @nodes << transition.origin_id
46
- @nodes << transition.destination_id
47
- @transitions << transition
48
- }
49
- }
50
- @nodes = @nodes.uniq
42
+ @transitions = []
43
+ @sm.states.values.each { |state|
44
+ state.transitions.values.each { |transition|
45
+ @nodes << transition.origin_id
46
+ if transition.destination_id.to_s =~ /_H$/
47
+ dest = transition.destination_id.to_s.sub(/_H$/, '').to_sym
48
+ @nodes << dest
49
+ @transitions << Transition.new(transition.origin_id, dest, transition.event.to_s + '_H', nil)
50
+ else
51
+ @nodes << transition.destination_id
52
+ @transitions << transition
53
+ end
54
+ }
55
+ if Superstate === state and state.startstate_id
56
+ @nodes << state.startstate_id
57
+ @transitions << Transition.new(state.id, state.startstate_id, :start, nil)
58
+ end
59
+ if state.default_transition
60
+ transition = state.default_transition
61
+ @transitions << Transition.new(transition.origin_id, transition.destination_id, '*', nil)
62
+ end
63
+ }
64
+ @transitions = @transitions.uniq
65
+ @nodes = @nodes.uniq
51
66
  end
52
67
 
53
68
  def build_full_graph
@@ -55,7 +70,29 @@ module Statemachine
55
70
 
56
71
  add_graph_header(builder, "main")
57
72
 
58
- @nodes.each { |node| add_node(builder, node) }
73
+ # Create graph tree
74
+ @sm.states.values.each { |state|
75
+ class << state
76
+ attr_reader :children
77
+ def add_child(child)
78
+ (@children ||= []) << child
79
+ end
80
+ end
81
+ }
82
+
83
+ roots = []
84
+ @sm.states.values.each { |state|
85
+ if state.superstate.id == :root
86
+ roots << state
87
+ else
88
+ state.superstate.add_child(state)
89
+ end
90
+ }
91
+
92
+ roots.each do |root|
93
+ add_node(builder, root)
94
+ end
95
+
59
96
  builder << endl
60
97
 
61
98
  @transitions.each do |transition|
@@ -83,6 +120,8 @@ module Statemachine
83
120
 
84
121
  def add_graph_header(builder, graph_name)
85
122
  builder << "digraph #{graph_name} {" << endl
123
+ builder << " compound=true; compress=true; rankdir=LR;"
124
+ builder << endl
86
125
  builder.indent!
87
126
  end
88
127
 
@@ -92,9 +131,24 @@ module Statemachine
92
131
  end
93
132
 
94
133
  def add_node(builder, node)
95
- builder << node
96
- builder << " [ href = \"#{node}.svg\"]"
97
- builder << endl
134
+ if Superstate === node
135
+ builder << "subgraph cluster_#{node.id} { "
136
+ builder.indent!
137
+ builder << endl
138
+ builder << "label = \"#{node.id}\"; style=rounded; #{node.id} "
139
+ builder << " [ style=\"rounded,filled\", shape=box, href=\"#{node.id}.svg\" ];"
140
+ builder << endl
141
+ node.children.each do |child|
142
+ add_node(builder, child)
143
+ end
144
+ builder.undent!
145
+ builder << "}"
146
+ builder << endl
147
+ else
148
+ builder << node.id
149
+ builder << " [shape=box, style=rounded, href=\"#{node.id}.svg\" ]"
150
+ builder << endl
151
+ end
98
152
  end
99
153
 
100
154
  def add_transition(builder, transition)
@@ -102,7 +156,11 @@ module Statemachine
102
156
  builder << " -> "
103
157
  builder << transition.destination_id
104
158
  builder << " [ "
105
- builder << "label = #{transition.event} "
159
+ builder << "label = \"#{transition.event}\" "
160
+ if transition.event.to_s =~ /_H$/
161
+ dest = 'cluster_' + transition.destination_id.to_s
162
+ builder << ", lhead=#{dest}"
163
+ end
106
164
  builder << "]"
107
165
  builder << endl
108
166
  end
@@ -2,7 +2,7 @@ module Statemachine
2
2
  module VERSION #:nodoc:
3
3
  unless defined? MAJOR
4
4
  MAJOR = 2
5
- MINOR = 1
5
+ MINOR = 2
6
6
  TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statemachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire: statemachine
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Statemachine is a ruby library for building Finite State Machines (FSM),
15
15
  also known as Finite State Automata (FSA).
@@ -205,7 +205,7 @@ rubyforge_project: statemachine
205
205
  rubygems_version: 1.8.24
206
206
  signing_key:
207
207
  specification_version: 3
208
- summary: Statemachine-2.1.0 - Statemachine Library for Ruby http://slagyr.github.com/statemachine
208
+ summary: Statemachine-2.2.0 - Statemachine Library for Ruby http://slagyr.github.com/statemachine
209
209
  test_files:
210
210
  - spec/action_invokation_spec.rb
211
211
  - spec/builder_spec.rb