support/ruby/collins-state/lib/collins/state/mixin_class_methods.rb
# Register a named event associated with the managed state
#
# Events are typically called as method invocations on the class, or as the result of a state
# being expired and a transition being specified.
#
# The example (and events in general) can be read as: Execute `:before_transition` before
# successfully transitioning to this event. Once transitioned, after `:expires` is reached the
# `:on_transition` action should be called, followed by the event associated with the specified
# `:transition`.
#
# @param [Symbol] name Event name
# @param [Hash] options Event options
# @option options [Symbol] :before_transition An action to execute successfully before transitioning to this state
# @option options [String] :desc A description of the event, required
# @option options [#to_i] :expires Do not consider `:on_transition` or `:transition` until after this amount of time
# @option options [Symbol] :on_transition Once the expiration time has passed execute this action
# @option options [Symbol] :transition The event to call after its appropriate for transition (due to timeout and successful `:before` calls)
# @return [Collins::SimpleCallback] the callback created for the action
#
# @example
#  event :stuff, :desc => 'I do things', :before_transition => :try_action, :expires => after(5, :minutes),
#                :transition => :after_stuff_event, :on_transition => :stuff_action
#
# @note A transition will not occur unless the :before_transition is successful (does not return false or throw an exception)
# @raise [KeyError] if the options hash is missing a `:desc` key
Register a named event associated with the managed state
Events are typically called as method invocations on the class, or as the result of a state
being expired and a transition being specified.

The example (and events in general) can be read as: Execute `:before_transition` before
successfully transitioning to this event.
Register a named event associated with the managed state Events are typically called as method invocations on the class or as the result of a state being expired and a transition being specified . The example ( and events in general ) can be read as : Execute ` : before_transition ` before successfully transitioning to this event .
def event name, options = {}
      name_sym = name.to_sym
      ::Collins::Option(options[:desc]).or_else {
        raise KeyError.new("Event #{name} is missing :desc key")
      }
      new_event = ::Collins::SimpleCallback.new(name_sym, options)
      @events[name_sym] = new_event
      new_event
    end
def event name , options = { } name_sym = name . to_sym :: Collins :: Option ( options [ :desc ] ) . or_else { raise KeyError . new ( "Event #{name} is missing :desc key" ) } new_event = :: Collins :: SimpleCallback . new ( name_sym , options ) @events [ name_sym ] = new_event new_event end
Register a named event associated with the managed state
Events are typically called as method invocations on the class, or as the result of a state
being expired and a transition being specified.
Register a named event associated with the managed state Events are typically called as method invocations on the class or as the result of a state being expired and a transition being specified .
the callback created for the action
the callback created for the action
Collins::SimpleCallback
[KeyError] if the options hash is missing a `:desc` key
[ KeyError ] if the options hash is missing a ` : desc ` key
name
options
:transition The event to call after its appropriate for transition (due to timeout and successful `:before` calls)
: transition The event to call after its appropriate for transition ( due to timeout and successful ` : before ` calls )
options Event options
options Event options
example
event :stuff, :desc => 'I do things', :before_transition => :try_action, :expires => after(5, :minutes), :transition => :after_stuff_event, :on_transition => :stuff_action
event : stuff : desc = > ' I do things ' : before_transition = > : try_action : expires = > after ( 5 : minutes ) : transition = > : after_stuff_event : on_transition = > : stuff_action
note
A transition will not occur unless the :before_transition is successful (does not return false or throw an exception)
A transition will not occur unless the : before_transition is successful ( does not return false or throw an exception )