Return to Snippet

Revision: 2714
at March 30, 2007 17:52 by drewr


Updated Code
Index: lib/acts_as_state_machine.rb
===================================================================
--- lib/acts_as_state_machine.rb	(revision 66)
+++ lib/acts_as_state_machine.rb	(working copy)
@@ -146,6 +146,10 @@
           self.send(self.class.state_column).to_sym
         end
       
+        def current_state_text
+          self.send("#{current_state}_text")
+        end
+
         # Returns what the next state for a given event would be, as a Ruby symbol.
         def next_state_for_event(event)
           ns = next_states_for_event(event)
@@ -214,10 +218,12 @@
         #   state :closed, Proc.new { |o| Mailer.send_notice(o) }
         # end
         def state(name, opts={})
+          text = opts.delete(:text) if opts.is_a?(Hash)
           state = SupportingClasses::State.new(name.to_sym, opts)
           read_inheritable_attribute(:states)[name.to_sym] = state
         
           define_method("#{state.name}?") { current_state == state.name }
+          define_method("#{state.name}_text") { text || "give me some :text" }
         end
         
         # Wraps ActiveRecord::Base.find to conveniently find all records in
@@ -265,4 +271,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end

Revision: 2713
at March 30, 2007 14:17 by drewr


Initial Code
Index: lib/acts_as_state_machine.rb
===================================================================
--- lib/acts_as_state_machine.rb	(revision 66)
+++ lib/acts_as_state_machine.rb	(working copy)
@@ -146,6 +146,10 @@
           self.send(self.class.state_column).to_sym
         end
       
+        def current_state_text
+          self.send(#{current_state}_text)
+        end
+
         # Returns what the next state for a given event would be, as a Ruby symbol.
         def next_state_for_event(event)
           ns = next_states_for_event(event)
@@ -214,10 +218,12 @@
         #   state :closed, Proc.new { |o| Mailer.send_notice(o) }
         # end
         def state(name, opts={})
+          text = opts.delete(:text) if opts.is_a?(Hash)
           state = SupportingClasses::State.new(name.to_sym, opts)
           read_inheritable_attribute(:states)[name.to_sym] = state
         
           define_method("#{state.name}?") { current_state == state.name }
+          define_method("#{state.name}_text") { text || "give me some :text" }
         end
         
         # Wraps ActiveRecord::Base.find to conveniently find all records in
@@ -265,4 +271,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end

Initial URL

                                

Initial Description

                                

Initial Title
Add text to AASM states

Initial Tags
plugin, rails

Initial Language
Diff