aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/state_machine/event.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-01-30 18:38:01 -0600
committerJoshua Peek <josh@joshpeek.com>2010-01-30 18:38:01 -0600
commitdb49c706b62e7ea2ab93f05399dbfddf5087ee0c (patch)
tree7f369bd2b77d620e344f19ba8156c597e2493f58 /activemodel/lib/active_model/state_machine/event.rb
parent657d85580e914caf368a8a12ff5642e4d979ab7e (diff)
downloadrails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.tar.gz
rails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.tar.bz2
rails-db49c706b62e7ea2ab93f05399dbfddf5087ee0c.zip
Axe AM state machine
We're going do it eventually, get it done before 3.0 is final.
Diffstat (limited to 'activemodel/lib/active_model/state_machine/event.rb')
-rw-r--r--activemodel/lib/active_model/state_machine/event.rb62
1 files changed, 0 insertions, 62 deletions
diff --git a/activemodel/lib/active_model/state_machine/event.rb b/activemodel/lib/active_model/state_machine/event.rb
deleted file mode 100644
index 30e9601dc2..0000000000
--- a/activemodel/lib/active_model/state_machine/event.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-module ActiveModel
- module StateMachine
- class Event
- attr_reader :name, :success
-
- def initialize(machine, name, options = {}, &block)
- @machine, @name, @transitions = machine, name, []
- if machine
- machine.klass.send(:define_method, "#{name}!") do |*args|
- machine.fire_event(name, self, true, *args)
- end
-
- machine.klass.send(:define_method, name.to_s) do |*args|
- machine.fire_event(name, self, false, *args)
- end
- end
- update(options, &block)
- end
-
- def fire(obj, to_state = nil, *args)
- transitions = @transitions.select { |t| t.from == obj.current_state(@machine ? @machine.name : nil) }
- raise InvalidTransition if transitions.size == 0
-
- next_state = nil
- transitions.each do |transition|
- next if to_state && !Array(transition.to).include?(to_state)
- if transition.perform(obj)
- next_state = to_state || Array(transition.to).first
- transition.execute(obj, *args)
- break
- end
- end
- next_state
- end
-
- def transitions_from_state?(state)
- @transitions.any? { |t| t.from? state }
- end
-
- def ==(event)
- if event.is_a? Symbol
- name == event
- else
- name == event.name
- end
- end
-
- def update(options = {}, &block)
- if options.key?(:success) then @success = options[:success] end
- if block then instance_eval(&block) end
- self
- end
-
- private
- def transitions(trans_opts)
- Array(trans_opts[:from]).each do |s|
- @transitions << StateTransition.new(trans_opts.merge({:from => s.to_sym}))
- end
- end
- end
- end
-end