Permalink
Browse files

Add a basic model generator.

  • Loading branch information...
wvanbergen committed Mar 15, 2011
1 parent f5fb7a9 commit a3c1a6a1d591c151b1e77543542f91eaf6237d2b
Showing with 17 additions and 2 deletions.
  1. +0 −1 lib/state_machine/audit_trail/railtie.rb
  2. +17 −1 lib/state_machine/audit_trail_generator.rb
@@ -1,5 +1,4 @@
class StateMachine::AuditTrail::Railtie < ::Rails::Railtie
-
generators do
require 'state_machine/audit_trail_generator'
end
@@ -1,5 +1,21 @@
require 'rails/generators'
-class StateMachine::AuditTrailGenerator < Rails::Generators::Base
+class StateMachine::AuditTrailGenerator < ::Rails::Generators::Base
+ source_root File.join(File.dirname(__FILE__), 'templates')
+
+ argument :source_model
+ argument :state_attribute, :default => 'state'
+ argument :transition_model, :default => nil
+
+
+ def create_model
+ Rails::Generators.invoke('model', [transition_class_name, "#{source_model.tableize}:references", "event:string", "from:string", "to:string", "created_at:timestamp", '--no-timestamps'])
+ end
+
+ protected
+
+ def transition_class_name
+ transition_model || "#{source_model.camelize}#{state_attribute.camelize}Transition"
+ end
end

0 comments on commit a3c1a6a

Please sign in to comment.