Skip to content

Commit

Permalink
Alias Machine#event as Machine#on
Browse files Browse the repository at this point in the history
  • Loading branch information
obrie committed Mar 3, 2009
1 parent cdec7f2 commit 88f8a0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,6 @@
== master

* Alias Machine#event as Machine#on
* Fix nil from/to states not being handled properly
* Simplify hooking callbacks into loopbacks
* Add simplified transition/callback requirement syntax
Expand Down
4 changes: 4 additions & 0 deletions lib/state_machine/machine.rb
Expand Up @@ -618,6 +618,9 @@ def state_for(object)
# Defines one or more events for the machine and the transitions that can
# be performed when those events are run.
#
# This method is also aliased as +on+ for improved compatibility with
# using a domain-specific language.
#
# == Instance methods
#
# The following instance methods are generated when a new event is defined
Expand Down Expand Up @@ -705,6 +708,7 @@ def event(*names, &block)

events.length == 1 ? events.first : events
end
alias_method :on, :event

# Creates a callback that will be invoked *before* a transition is
# performed so long as the given requirements match the transition.
Expand Down
5 changes: 5 additions & 0 deletions test/unit/machine_test.rb
Expand Up @@ -937,6 +937,11 @@ def test_should_evaluate_block_within_event_context
assert responded
end

def test_should_be_aliased_as_on
event = @machine.on(:ignite) {}
assert_equal :ignite, event.name
end

def test_should_have_events
event = @machine.event(:ignite)
assert_equal [event], @machine.events.to_a
Expand Down

0 comments on commit 88f8a0d

Please sign in to comment.