Class: GithubControl::Collaborators

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/github-control/collaborators.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Collaborators

Returns a new instance of Collaborators.



7
8
9
# File 'lib/github-control/collaborators.rb', line 7

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



5
6
7
# File 'lib/github-control/collaborators.rb', line 5

def repository
  @repository
end

Instance Method Details

#create(user) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/github-control/collaborators.rb', line 11

def create(user)
  @repository.owner.cli.post("/repos/collaborators/" \
    "#{@repository.name}/add/#{user}")
  if loaded?
    set << @repository.owner.cli.user_for(user)
  else
    set
  end
end

#delete(user) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/github-control/collaborators.rb', line 21

def delete(user)
  @repository.owner.cli.post("/repos/collaborators/" \
    "#{@repository.name}/remove/#{user}")
  if loaded?
    set.delete_if { |u| u.name == user }
  end
end

#each(&block) ⇒ Object



29
30
31
# File 'lib/github-control/collaborators.rb', line 29

def each(&block)
  set.each(&block)
end

#json_dataObject



47
48
49
50
# File 'lib/github-control/collaborators.rb', line 47

def json_data
  @repository.owner.cli.post("/repos/show/" \
    "#{@repository.owner.name}/#{@repository.name}/collaborators")
end

#loaded?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/github-control/collaborators.rb', line 37

def loaded?
  @set
end

#setObject



41
42
43
44
45
# File 'lib/github-control/collaborators.rb', line 41

def set
  @set ||= json_data["collaborators"].map { |name|
    @repository.owner.cli.user_for(name)
  }
end

#sizeObject



33
34
35
# File 'lib/github-control/collaborators.rb', line 33

def size
  set.size
end