lib/finite_machine/dsl.rb in finite_machine-0.2.0 vs lib/finite_machine/dsl.rb in finite_machine-0.3.0

- old
+ new

@@ -46,22 +46,28 @@ self.defer = true end # Define initial state # - # @params [String, Hash] value + # @param [String, Hash] value # # @api public def initial(value) state, name, self.defer = parse(value) self.initial_event = name event = proc { event name, from: FiniteMachine::DEFAULT_STATE, to: state } machine.events.call(&event) end - def target(value) - machine.env.target = value + # Attach state machine to an object. This allows state machine + # to initiate events in the context of a particular object. + # + # @param [Object] object + # + # @api public + def target(object) + machine.env.target = object end # Define terminal state # # @api public @@ -92,11 +98,11 @@ private # Parse initial options # - # @params [String, Hash] value + # @param [String, Hash] value # # @return [Array[Symbol,String]] # # @api private def parse(value) @@ -122,24 +128,25 @@ # @api public def event(name, attrs = {}, &block) sync_exclusive do _transition = Transition.new(machine, attrs.merge!(name: name)) _transition.define + _transition.define_state_methods _transition.define_event end end end # EventsDSL class ErrorsDSL < GenericDSL - def initialize(machine) - super(machine) - machine.error_handlers = [] - end - # Add error handler # # @param [Array] exceptions + # + # @example + # handle InvalidStateError, with: :log_errors + # + # @return [Array[Exception]] # # @api public def handle(*exceptions, &block) machine.handle(*exceptions, &block) end