lib/finite_machine/dsl.rb in finite_machine-0.9.2 vs lib/finite_machine/dsl.rb in finite_machine-0.10.0
- old
+ new
@@ -121,10 +121,31 @@
else
machine.env.target = object
end
end
+ # Use alternative name for target
+ #
+ # @example
+ # target_alias: :car
+ #
+ # callbacks {
+ # on_transition do |event|
+ # car.state = event.to
+ # end
+ # }
+ #
+ # @param [Symbol] alias_name
+ # the name to alias target to
+ #
+ # @return [FiniteMachine::StateMachine]
+ #
+ # @api public
+ def alias_target(alias_name)
+ machine.env.aliases << alias_name.to_sym
+ end
+
# Define terminal state
#
# @example
# terminal :red
#
@@ -168,18 +189,26 @@
# @api public
def handlers(&block)
machine.errors.call(&block)
end
+ # Decide whether to log transitions
+ #
+ # @api public
+ def log_transitions(value)
+ machine.log_transitions = value
+ end
+
private
# Initialize state machine properties based off attributes
#
# @api private
def initialize_attrs
attrs[:initial] and initial(attrs[:initial])
attrs[:target] and target(attrs[:target])
attrs[:terminal] and terminal(attrs[:terminal])
+ log_transitions(attrs.fetch(:log_transitions, false))
end
# Parse initial options
#
# @param [Object] value