1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Merge pull request #131 from enbaglisash/refactor_on_state_machine_class

move setting initial_state codes to StateMachine class
This commit is contained in:
Thorsten Böttger 2014-05-28 20:11:58 +02:00
commit b0c195f3a0
2 changed files with 7 additions and 1 deletions

View file

@ -31,7 +31,6 @@ module AASM
# define a state
def state(name, options={})
@state_machine.add_state(name, @klass, options)
@state_machine.initial_state = name if options[:initial] || !@state_machine.initial_state
@klass.send(:define_method, "#{name.to_s}?") do
aasm.current_state == name

View file

@ -28,8 +28,15 @@ module AASM
end
def add_state(name, klass, options)
set_initial_state(name, options)
@states << AASM::State.new(name, klass, options) unless @states.include?(name)
end
private
def set_initial_state(name, options)
@initial_state = name if options[:initial] || !initial_state
end
end # StateMachine
end # AASM