Class: GithubControl::Repositories

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

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Repositories

Returns a new instance of Repositories.



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

def initialize(user)
  @user  = user
end

Instance Method Details

#[](name) ⇒ Object



20
21
22
# File 'lib/github-control/repositories.rb', line 20

def [](name)
  get(name)
end

#clearObject



43
44
45
# File 'lib/github-control/repositories.rb', line 43

def clear
  @set = nil
end

#create(name, access) ⇒ Object



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

def create(name, access)
  @user.cli.post("/repos/create",
    :name    => name,
    :public  => access == :public ? 1 : 0
  )

  repo = Repository.new(@user, name, access)
  set << repo
  repo
end

#delete(name) ⇒ Object



28
29
30
31
32
33
# File 'lib/github-control/repositories.rb', line 28

def delete(name)
  response = @user.cli.post("/repos/delete/#{name}")
  @user.cli.post("/repos/delete/#{name}",
    :delete_token => response["delete_token"])
  any? && set.delete(name)
end

#destroyObject



35
36
37
# File 'lib/github-control/repositories.rb', line 35

def destroy
  each { |r| delete(r.name) }
end

#each(&block) ⇒ Object



39
40
41
# File 'lib/github-control/repositories.rb', line 39

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  ! any?
end

#get(name) ⇒ Object



24
25
26
# File 'lib/github-control/repositories.rb', line 24

def get(name)
  set.detect { |r| r.name == name }
end

#sizeObject



51
52
53
# File 'lib/github-control/repositories.rb', line 51

def size
  set.size
end