Class: OsCtld::DB::Users

Inherits:
PooledList show all
Defined in:
lib/osctld/db/users.rb

Instance Attribute Summary

Attributes inherited from List

#objects

Instance Method Summary collapse

Methods inherited from PooledList

#contains?, #find

Methods inherited from List

#contains?, #count, #find, #get, instance, #sync

Constructor Details

#initialize(*_) ⇒ Users

Returns a new instance of Users



14
15
16
17
18
# File 'lib/osctld/db/users.rb', line 14

def initialize(*_)
  super
  @name_index = OsCtl::Lib::Index.new { |u| u.name }
  @ugid_index = OsCtl::Lib::Index.new { |u| u.ugid }
end

Instance Method Details

#add(user) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/osctld/db/users.rb', line 20

def add(user)
  sync do
    super
    @name_index << user
    @ugid_index << user
  end
end

#by_name(name) ⇒ Object



37
38
39
# File 'lib/osctld/db/users.rb', line 37

def by_name(name)
  sync { @name_index[name] }
end

#by_ugid(ugid) ⇒ Object



41
42
43
# File 'lib/osctld/db/users.rb', line 41

def by_ugid(ugid)
  sync { @ugid_index[ugid] }
end

#remove(user) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/osctld/db/users.rb', line 28

def remove(user)
  sync do
    super
    @name_index.delete(user)
    @ugid_index.delete(user)
    user
  end
end