Class: Phabricator::Project

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

Constant Summary collapse

@@cached_projects =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Project

Returns a new instance of Project.



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

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#phidObject (readonly)

Returns the value of attribute phid.



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

def phid
  @phid
end

Class Method Details

.find_by_name(name) ⇒ Object



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

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_projects[name]

  @@cached_projects[name]
end

.populate_allObject



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

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

  response['result'].each do |phid, data|
    project = Project.new(data)
    @@cached_projects[project.name] = project
  end
end