support/ruby/collins-state/lib/collins/state/mixin_class_methods.rb
# Register a managed state for this class
#
# @note Only one managed state per class is allowed.
# @param [Symbol] name The name of the managed state, e.g. `:some_process`
# @param [Hash] options Managed state options
# @option options [Symbol] :initial First event to fire if the state is being initialized
# @yieldparam [Collins::Client] block Managed state description, registering events and actions
#
# @example
#  manage_state :a_process, :initial => :start do |client|
#    action :log_it do |asset|
#      client.log! asset, "Did some logging"
#    end
#    event :start, :desc => 'Initial state', :expires => after(30, :minutes), :on_transition => :log_it, :transition => :done
#    event :done, :desc => 'Done'
#  end
Register a managed state for this class
Register a managed state for this class
def manage_state name, options = {}, &block
      @actions = {}
      @events = {}
      @managed_state = ::Collins::SimpleCallback.new(name, options, block)
    end
def manage_state name , options = { } , & block @actions = { } @events = { } @managed_state = :: Collins :: SimpleCallback . new ( name , options , block ) end
Register a managed state for this class
Register a managed state for this class
name
options
:initial First event to fire if the state is being initialized
: initial First event to fire if the state is being initialized
block
block Managed state description, registering events and actions
block Managed state description registering events and actions
note
Only one managed state per class is allowed.
Only one managed state per class is allowed .
example
manage_state :a_process, :initial => :start do |client| action :log_it do |asset| client.log. asset, "Did some logging" end event :start, :desc => 'Initial state', :expires => after(30, :minutes), :on_transition => :log_it, :transition => :done event :done, :desc => 'Done' end
manage_state : a_process : initial = > : start do |client| action : log_it do |asset| client . log . asset " Did some logging " end event : start : desc = > ' Initial state ' : expires = > after ( 30 : minutes ) : on_transition = > : log_it : transition = > : done event : done : desc = > ' Done ' end