Method: Fargo::Supports::RemoteFileList#file_list

Defined in:
lib/fargo/supports/remote_file_list.rb

#file_list(nick) ⇒ Object

Lazily load the file list for the nick. Subscribe to the client for the event :file_list to get notified.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fargo/supports/remote_file_list.rb', line 18

def file_list nick
  if @file_list.has_key?(nick)
    return parse_file_list(@file_list[nick], nick)
  elsif @getting_file_list[nick]
    return true
  end

  subscription_id = channel.subscribe do |type, map|
    case type
      when :download_finished, :download_failed, :connection_timeout
        if map[:nick] == nick
          @file_list[nick] = map[:file]

          channel.unsubscribe subscription_id
          channel << [:file_list,
              {:nick => nick, :list => @file_list[nick]}]

          @getting_file_list.delete nick
        end
    end
  end

  @getting_file_list[nick] = true
  download nick, 'files.xml.bz2'

  EventMachine.add_timer 60 do
    @file_list.delete nick
    @getting_file_list.delete nick
  end
end