Module: IIRC::IRCv3::Batches

Included in:
IIRC::IRCv3Bot
Defined in:
lib/iirc/modules/ircv3/batches.rb

Instance Method Summary collapse

Instance Method Details

#batches_in_flightObject



14
15
16
# File 'lib/iirc/modules/ircv3/batches.rb', line 14

def batches_in_flight
  @batches_in_flight ||= {}
end

#configure_batchesObject



10
11
12
# File 'lib/iirc/modules/ircv3/batches.rb', line 10

def configure_batches
  hook :receive_batches
end

#receive_batches(evt) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/iirc/modules/ircv3/batches.rb', line 18

def receive_batches evt
  return if evt.is_a? Batch # fully formed synthetic batch

  if evt.verb == :batch
    ± = evt.target[0]
    id = evt.target[1..]

    if ± == '+'
      batches_in_flight[id] = Batch.new(
        sender: evt.sender,
        verb: evt.verb,
        args: evt.args.dup.tap { |args| args[0] = id },
        tags: evt.tags,
      )
    else
      fire! :batch, batches_in_flight.delete(id)
    end
    raise StopIteration
  elsif evt.tags['batch']
    id = evt.tags['batch']
    batches_in_flight[id].events << evt
  end
end