Module: Fargo::Supports::FileList

Included in:
Client
Defined in:
lib/fargo/supports/file_list.rb

Defined Under Namespace

Classes: Listing

Instance Method Summary collapse

Instance Method Details

#file_list(nick) ⇒ Object

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fargo/supports/file_list.rb', line 11

def file_list nick
  @file_list ||= {}
  return parse_file_list(@file_list[nick]) if @file_list.has_key?(nick)

  file_gotten = lambda{ |type, map|
    case type
      when :download_finished, :download_failed, :connection_timeout
        if map[:nick] == nick
          @file_list[nick] = map[:file]
          unsubscribe &file_gotten
          publish :file_list, :nick => nick, :list => @file_list[nick]
        end
    end
  }

  subscribe &file_gotten

  download nick, 'files.xml.bz2'
end

#file_list!(nick, timeout = 10) ⇒ Object

Wait for the results to arrive, timed out after some time



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fargo/supports/file_list.rb', line 32

def file_list! nick, timeout = 10
  @file_list ||= {}
  return parse_file_list(@file_list[nick]) if @file_list.has_key?(nick)

  list = nil
  list_gotten = lambda{ |type, map|
    if type == :file_list && map[:nick] == nick
      list = map[:list]
      true
    else
      false
    end
  }

  timeout_response(timeout, list_gotten){ file_list nick }

  parse_file_list list
end