diff options
author | rick <technoweenie@gmail.com> | 2008-06-28 11:01:40 -0700 |
---|---|---|
committer | rick <technoweenie@gmail.com> | 2008-06-28 11:01:40 -0700 |
commit | a9d9ca16c739ec39a192d29c62f760e51040fc6e (patch) | |
tree | d425cb2a79d947f9cce89819e02f2ce8b98c8c73 /activemodel/lib/active_model/state_machine/event.rb | |
parent | 74cb05698684f237a7eb91afadec0020d8910c70 (diff) | |
download | rails-a9d9ca16c739ec39a192d29c62f760e51040fc6e.tar.gz rails-a9d9ca16c739ec39a192d29c62f760e51040fc6e.tar.bz2 rails-a9d9ca16c739ec39a192d29c62f760e51040fc6e.zip |
converted tests for more complex state transitions
Diffstat (limited to 'activemodel/lib/active_model/state_machine/event.rb')
-rw-r--r-- | activemodel/lib/active_model/state_machine/event.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/state_machine/event.rb b/activemodel/lib/active_model/state_machine/event.rb index cc7d563214..ea4df343de 100644 --- a/activemodel/lib/active_model/state_machine/event.rb +++ b/activemodel/lib/active_model/state_machine/event.rb @@ -3,9 +3,8 @@ module ActiveModel class Event attr_reader :name, :success - def initialize(name, options = {}, &block) - @name, @transitions = name, [] - machine = options.delete(:machine) + def initialize(machine, name, options = {}, &block) + @machine, @name, @transitions = machine, name, [] if machine machine.klass.send(:define_method, "#{name.to_s}!") do |*args| machine.fire_event(name, self, true, *args) @@ -19,7 +18,7 @@ module ActiveModel end def fire(obj, to_state = nil, *args) - transitions = @transitions.select { |t| t.from == obj.current_state } + transitions = @transitions.select { |t| t.from == obj.current_state(@machine ? @machine.name : nil) } raise InvalidTransition if transitions.size == 0 next_state = nil |