Permalink
Browse files

DRY up SupportingClasses::State.

  • Loading branch information...
Dray Lacy
Dray Lacy committed Apr 11, 2008
1 parent 6491939 commit 95122980e5a767fa56d20d6be8b39da9a1bd068d
Showing with 11 additions and 11 deletions.
  1. +11 −11 lib/acts_as_state_machine.rb
@@ -11,29 +11,29 @@ def self.included(base) #:nodoc:
end
module SupportingClasses
+ # Default transition action. Always returns true.
+ NOOP = lambda { |o| true }
+
class State
attr_reader :name
- def initialize(name, opts)
- @name, @opts = name, opts
+ def initialize(name, options)
+ @name = name
+ @after = Array(options[:after])
+ @enter = options[:enter] || NOOP
+ @exit = options[:exit] || NOOP
end
def entering(record)
- enteract = @opts[:enter]
- record.send(:run_transition_action, enteract) if enteract
+ record.send(:run_transition_action, @enter)
end
def entered(record)
- afteractions = @opts[:after]
- return unless afteractions
- Array(afteractions).each do |afteract|
- record.send(:run_transition_action, afteract)
- end
+ @after.each { |action| record.send(:run_transition_action, action) }
end
def exited(record)
- exitact = @opts[:exit]
- record.send(:run_transition_action, exitact) if exitact
+ record.send(:run_transition_action, @exit)
end
end

0 comments on commit 9512298

Please sign in to comment.