Class: Phabricator::User

Inherits:
Object
  • Object
show all
Defined in:
lib/phabricator/user.rb

Constant Summary collapse

@@cached_users =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



28
29
30
31
# File 'lib/phabricator/user.rb', line 28

def initialize(attributes)
  @phid = attributes['phid']
  @name = attributes['userName']
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/phabricator/user.rb', line 8

def name
  @name
end

#phidObject (readonly)

Returns the value of attribute phid.



7
8
9
# File 'lib/phabricator/user.rb', line 7

def phid
  @phid
end

Class Method Details

.find_by_name(name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/phabricator/user.rb', line 20

def self.find_by_name(name)
  # Re-populate if we couldn't find it in the cache (this applies to
  # if the cache is empty as well).
  populate_all unless @@cached_users[name]

  @@cached_users[name]
end

.populate_allObject



10
11
12
13
14
15
16
17
18
# File 'lib/phabricator/user.rb', line 10

def self.populate_all
  response = JSON.parse(client.request(:post, 'user.query'))

  response['result'].each do |data|
    user = User.new(data)
    @@cached_users[user.name] = user
  end

end