Permalink
Browse files

Added support for aasm in addition to acts_as_state_machine.

  • Loading branch information...
1 parent a7c4629 commit 99fb7b02dbc0edd1cf945da6f427ab16edcca862 @tobias tobias committed Sep 23, 2010
Showing with 54 additions and 26 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 VERSION.yml
  3. +41 −14 lib/railroad/aasm_diagram.rb
  4. +11 −11 railroad.gemspec
View
@@ -7,3 +7,4 @@ pkg
nbproject
/.gvimrc
/.vim*
+.rvmrc
View
@@ -1,5 +1,5 @@
---
-:minor: 9
+:minor: 10
:build:
:patch: 0
:major: 0
@@ -13,7 +13,7 @@ class AasmDiagram < AppDiagram
def initialize(options = OptionsStruct.new)
#options.exclude.map! {|e| e = "app/models/" + e}
- super options
+ super options
@graph.diagram_type = 'Models'
# Processed habtm associations
@habtm = []
@@ -26,7 +26,7 @@ def generate
process_class extract_class_name(f).constantize
end
end
-
+
def get_files(prefix ='')
files = !@options.specify.empty? ? Dir.glob(@options.specify) : Dir.glob(prefix << "app/models/**/*.rb")
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
@@ -35,7 +35,7 @@ def get_files(prefix ='')
end
private
-
+
# Load model classes
def load_classes
begin
@@ -51,32 +51,59 @@ def load_classes
# Process a model class
def process_class(current_class)
-
+
STDERR.print "\tProcessing #{current_class}\n" if @options.verbose
-
+
# Only interested in acts_as_state_machine models.
- return unless current_class.respond_to?'states'
-
+ process_acts_as_state_machine_class(current_class) if current_class.respond_to?(:states)
+ process_aasm_class(current_class) if current_class.respond_to?(:aasm_states)
+ end # process_class
+
+ def process_acts_as_state_machine_class(current_class)
node_attribs = []
node_type = 'aasm'
+ STDERR.print "\t\tprocessing as acts_as_state_machine\n" if @options.verbose
current_class.states.each do |state_name|
state = current_class.read_inheritable_attribute(:states)[state_name]
node_shape = (current_class.initial_state === state_name) ? ", peripheries = 2" : ""
node_attribs << "#{current_class.name.downcase}_#{state_name} [label=#{state_name} #{node_shape}];"
end
@graph.add_node [node_type, current_class.name, node_attribs]
-
+
current_class.read_inheritable_attribute(:transition_table).each do |event_name, event|
event.each do |transition|
@graph.add_edge [
- 'event',
- current_class.name.downcase + "_" + transition.from.to_s,
- current_class.name.downcase + "_" + transition.to.to_s,
- event_name.to_s
- ]
+ 'event',
+ current_class.name.downcase + "_" + transition.from.to_s,
+ current_class.name.downcase + "_" + transition.to.to_s,
+ event_name.to_s
+ ]
end
end
- end # process_class
+ end
+
+ def process_aasm_class(current_class)
+ node_attribs = []
+ node_type = 'aasm'
+
+ STDERR.print "\t\tprocessing as aasm\n" if @options.verbose
+ current_class.aasm_states.each do |state|
+ node_shape = (current_class.aasm_initial_state === state.name) ? ", peripheries = 2" : ""
+ node_attribs << "#{current_class.name.downcase}_#{state.name} [label=#{state.name} #{node_shape}];"
+ end
+ @graph.add_node [node_type, current_class.name, node_attribs]
+
+ current_class.aasm_events.each do |event_name, event|
+ event.all_transitions.each do |transition|
+ @graph.add_edge [
+ 'event',
+ current_class.name.downcase + "_" + transition.from.to_s,
+ current_class.name.downcase + "_" + transition.to.to_s,
+ event_name.to_s
+ ]
+ end
+ end
+ end
end # class AasmDiagram
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{railroad}
- s.version = "0.9.0"
+ s.version = "0.10.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Peter Hoeg", "Javier Smaldone"]
- s.date = %q{2010-08-02}
+ s.date = %q{2010-09-23}
s.default_executable = %q{railroad}
s.description = %q{A DOT diagram generator for Ruby on Rail applications}
s.email = ["peter@hoeg.com", "p.hoeg@northwind.sg", "javier@smaldone.com.ar"]
@@ -57,19 +57,19 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.7}
s.summary = %q{A DOT diagram generator for Ruby on Rail applications}
s.test_files = [
- "spec/aasm_diagram_spec.rb",
- "spec/app_diagram_spec.rb",
- "spec/controllers_diagram_spec.rb",
+ "spec/app_diagram_spec.rb",
"spec/diagram_graph_spec.rb",
- "spec/file_fixture/app/controllers/application_controller.rb",
- "spec/file_fixture/app/controllers/dummy1_controller.rb",
- "spec/file_fixture/app/controllers/dummy2_controller.rb",
- "spec/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb",
+ "spec/controllers_diagram_spec.rb",
+ "spec/models_diagram_spec.rb",
+ "spec/spec_helper.rb",
+ "spec/aasm_diagram_spec.rb",
"spec/file_fixture/app/models/dummy1.rb",
"spec/file_fixture/app/models/dummy2.rb",
"spec/file_fixture/app/models/sub-dir/sub_dummy.rb",
- "spec/models_diagram_spec.rb",
- "spec/spec_helper.rb"
+ "spec/file_fixture/app/controllers/dummy2_controller.rb",
+ "spec/file_fixture/app/controllers/application_controller.rb",
+ "spec/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb",
+ "spec/file_fixture/app/controllers/dummy1_controller.rb"
]
if s.respond_to? :specification_version then

0 comments on commit 99fb7b0

Please sign in to comment.