Class: Github::Backup

Inherits:
Object
  • Object
show all
Includes:
Octopi
Defined in:
lib/github-backup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, backup_root) ⇒ Backup

Returns a new instance of Backup.



12
13
14
15
16
# File 'lib/github-backup.rb', line 12

def initialize(username, backup_root)
  @username    = username
  @backup_root = backup_root
  @debug = false
end

Instance Attribute Details

#backup_rootObject (readonly)

Returns the value of attribute backup_root.



10
11
12
# File 'lib/github-backup.rb', line 10

def backup_root
  @backup_root
end

#debugObject (readonly)

Returns the value of attribute debug.



10
11
12
# File 'lib/github-backup.rb', line 10

def debug
  @debug
end

#usernameObject (readonly)

Returns the value of attribute username.



10
11
12
# File 'lib/github-backup.rb', line 10

def username
  @username
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/github-backup.rb', line 18

def execute
  FileUtils::mkdir_p(backup_root)
  authenticated do |api|
    repositories = User.find(username).repositories.sort_by { |r| r.name }
    repositories.each do |repository|
      puts "Backing up: #{repository.name}"
      backup_repository repository
    end
  end
rescue Errno::ENOENT
  puts "Please install git and create a ~/.gitconfig"
  puts "  See: http://github.com/guides/tell-git-your-user-name-and-email-address"
rescue NoMethodError
  puts "Please add a [github] section to your ~/.gitconfig"
  puts "  See: http://github.com/guides/tell-git-your-user-name-and-email-address"
end