def register(name, participant, options, block)

      entry = to_entry(name, participant, options, block)

      key = entry.first
      options = entry.last.last

      list = get_list

      position = options['position'] || options['pos'] || 'last'

      if position == 'before'

        position = list['list'].index { |e| e.first == key } || -1

      elsif position == 'after'

        position = (list['list'].rindex { |e| e.first == key } || -2) + 1

      elsif position == 'over'

        position = list['list'].index { |e| e.first == key } || -1
        list['list'].delete_at(position) unless position == -1

      elsif options.delete('override') != false

        list['list'].delete_if { |e| e.first == key }
          # enforces only one instance of a participant per key/regex
      end

      case position
        when 'last' then list['list'] << entry
        when 'first' then list['list'].unshift(entry)
        when Fixnum then list['list'].insert(position, entry)
        else raise "cannot insert participant at position '#{position}'"
      end

      if r = @context.storage.put(list)
        #
        # if put returns something it means the put failed, have to redo the
        # work...
        #
        return register(name, participant, options, block)
      end

      if entry.last.first == 'Ruote::StorageParticipant'
        Ruote::StorageParticipant.new(@context)
      else
        nil
      end
    end
def register(name, participant, options, block)

      entry = to_entry(name, participant, options, block)

      key = entry.first
      options = entry.last.last

      list = get_list

      position = options['position'] || options['pos'] || 'last'

      if position == 'before'

        position = list['list'].index { |e| e.first == key } || -1

      elsif position == 'after'

        position = (list['list'].rindex { |e| e.first == key } || -2) + 1

      elsif position == 'over'

        position = list['list'].index { |e| e.first == key } || -1
        list['list'].delete_at(position) unless position == -1

      elsif options.delete('override') != false

        list['list'].delete_if { |e| e.first == key }
          # enforces only one instance of a participant per key/regex
      end

      case position
        when 'last' then list['list'] << entry
        when 'first' then list['list'].unshift(entry)
        when Fixnum then list['list'].insert(position, entry)
        else raise "cannot insert participant at position '#{position}'"
      end

      if r = @context.storage.put(list)
        #
        # if put returns something it means the put failed, have to redo the
        # work...
        #
        return register(name, participant, options, block)
      end

      if entry.last.first == 'Ruote::StorageParticipant'
        Ruote::StorageParticipant.new(@context)
      else
        nil
      end
    end
Registers a participant. Called by Engine#register_participant.