lib/simplestate/state_holder.rb in simplestate-2.0.6 vs lib/simplestate/state_holder.rb in simplestate-2.0.7
- old
+ new
@@ -1,19 +1,19 @@
class StateHolder < SimpleDelegator
- attr_reader :initial_state, :state_history
+ attr_reader :initial_state
- def initialize(initial_state:, state_history: StateHistory.new, opts: {})
- @initial_state = initial_state
+ def initialize( initial_state: nil,
+ state_history: StateHistory.new,
+ state_list: StateList.new,
+ opts: {})
@state_history = state_history
- @state_list = StateList.new
-
- super(NullState.new)
+ @state_list = state_list
+ super
end
- def start
- state_history << current_state.symbol
- transition_to(initial_state)
+ def start(init_state=initial_state)
+ enter_new_state(init_state)
end
def transition_to(state)
leave_old_state
enter_new_state(state)
@@ -31,10 +31,10 @@
def hx_size_limit
state_history.hx_size_limit
end
private
- attr_reader :state_list
+ attr_reader :state_list, :state_history
def leave_old_state
current_state.__send__(:exit)
end
def enter_new_state(state)