Method: CEML::Driver#subpost

Defined in:
lib/ceml/driver.rb

#subpost(incident, players, metadata, *updated_players) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/ceml/driver.rb', line 160

def subpost incident, players, , *updated_players
  updated_players.each do |player|
    player_id = player[:id]
    player[:roles] = Set.new([*player[:roles] || []])
    player[:roles] << :agents << :players << :both << :all << :each << :everyone
    if existing_player = players.find{ |p| p[:id] == player_id }
      existing_player[:roles] += player.delete :roles
      existing_player.update player
    else
      players << player
    end
  end
  incident.run(players) do |player, meth, what|
    meth = "player_#{meth}"
    log "[#{incident.id}] #{meth}: #{player[:id]} #{what.inspect}"
    if respond_to? meth
      .update :player => player, :players => players, :id => incident.id
      result = send(meth, , what)
      .delete :player
      .delete :players
      result
    end
  end
end