Class: Atig::Db::Lists

Inherits:
Object
  • Object
show all
Includes:
Listenable, Transaction
Defined in:
lib/atig/db/lists.rb

Constant Summary

Constants included from Listenable

Atig::Db::Listenable::SingleThread

Instance Method Summary collapse

Methods included from Transaction

#debug, #init, #transaction

Methods included from ExceptionUtil

daemon, safe

Methods included from Listenable

#listen

Constructor Details

#initialize(name) ⇒ Lists

Returns a new instance of Lists.



11
12
13
14
15
16
# File 'lib/atig/db/lists.rb', line 11

def initialize(name)
  @name    = name
  @lists   = {}
  @on_invalidated = lambda{|*_| }
  @members = nil
end

Instance Method Details

#[](name) ⇒ Object



48
49
50
# File 'lib/atig/db/lists.rb', line 48

def [](name)
  @lists[name]
end

#each(&f) ⇒ Object



69
70
71
72
73
# File 'lib/atig/db/lists.rb', line 69

def each(&f)
  @lists.each do|name,users|
    f.call name,users.users
  end
end

#find_by_list_name(name) ⇒ Object



65
66
67
# File 'lib/atig/db/lists.rb', line 65

def find_by_list_name(name)
  @lists[name].users
end

#find_by_screen_name(name) ⇒ Object



60
61
62
63
# File 'lib/atig/db/lists.rb', line 60

def find_by_screen_name(name)
  return [] unless @members
  @members[name]
end

#invalidate(name) ⇒ Object



52
53
54
# File 'lib/atig/db/lists.rb', line 52

def invalidate(name)
  @on_invalidated.call name
end

#on_invalidated(&f) ⇒ Object



56
57
58
# File 'lib/atig/db/lists.rb', line 56

def on_invalidated(&f)
  @on_invalidated = f
end

#update(lists) ⇒ Object



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
# File 'lib/atig/db/lists.rb', line 18

def update(lists)
  @members = Hash.new{|hash,key|
    hash[key] = []
  }

  (lists.keys  - @lists.keys).each do|name|
    list = Followings.new(@name % name)
    list.listen{|kind,users|
      notify kind,name,users
    }
    @lists[name] = list
    notify :new, name
  end

  (@lists.keys - lists.keys).each do|x|
    @lists.delete x
    notify :del,x
  end

  lists.each do|name,users|
    @lists[name].update users
  end

  lists.each do|list, users|
    users.each do|user|
      @members[user.screen_name] << list
    end
  end
end