deprecate usage of Event#all_transitions (getter method)

This commit is contained in:
Thorsten Böttger 2013-11-30 22:49:39 +01:00
parent c5ae69ca64
commit a35d7db34c
2 changed files with 16 additions and 16 deletions

View File

@ -36,9 +36,9 @@ module AASM
@transitions.select { |t| t.to == state }
end
# deprecated
# TODO remove this method in v4.0.0
def all_transitions
# warn "Event#all_transitions is deprecated and will be removed in version 3.2.0; please use Event#transitions instead!"
warn "Event#all_transitions is deprecated and will be removed in version 4.0.0; please use Event#transitions instead!"
transitions
end
@ -54,6 +54,19 @@ module AASM
end
end
## DSL interface
def transitions(definitions=nil)
if definitions # define new transitions
# Create a separate transition for each from state to the given state
Array(definitions[:from]).each do |s|
@transitions << AASM::Transition.new(definitions.merge({:from => s.to_sym}))
end
# Create a transition if to is specified without from (transitions from ANY state)
@transitions << AASM::Transition.new(definitions) if @transitions.empty? && definitions[:to]
end
@transitions
end
private
def update(options = {}, &block)
@ -106,19 +119,6 @@ module AASM
end
end
## DSL interface
def transitions(trans_opts=nil)
if trans_opts # define new transitions
# Create a separate transition for each from state to the given state
Array(trans_opts[:from]).each do |s|
@transitions << AASM::Transition.new(trans_opts.merge({:from => s.to_sym}))
end
# Create a transition if to is specified without from (transitions from ANY state)
@transitions << AASM::Transition.new(trans_opts) if @transitions.empty? && trans_opts[:to]
end
@transitions
end
[:after, :before, :error, :success].each do |callback_name|
define_method callback_name do |*args, &block|
options[callback_name] = Array(options[callback_name])

View File

@ -26,7 +26,7 @@ describe 'adding an event' do
end
it 'should create transitions' do
transitions = event.all_transitions
transitions = event.transitions
transitions[0].from.should == :open
transitions[0].to.should == :closed
transitions[1].from.should == :received