Class: GithubBackup::Backup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, backup_root, options = {}) ⇒ Backup

Returns a new instance of Backup.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/github-backup/backup.rb', line 5

def initialize(username, backup_root, options = {})
  @username    = username
  @backup_root = backup_root
  @options     = options
  @debug       = false

  unless options.key?(:token)
    config = read_gitconfig
    if config.key?('github')
      options[:token] = config['github'].fetch('token', nil)
    end
  end

  if options[:token]
    @client = Octokit::Client.new(:access_token => options[:token])
  else
    @client = Octokit::Client.new
  end
end

Instance Attribute Details

#backup_rootObject (readonly)

Returns the value of attribute backup_root.



3
4
5
# File 'lib/github-backup/backup.rb', line 3

def backup_root
  @backup_root
end

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/github-backup/backup.rb', line 3

def client
  @client
end

#debugObject (readonly)

Returns the value of attribute debug.



3
4
5
# File 'lib/github-backup/backup.rb', line 3

def debug
  @debug
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/github-backup/backup.rb', line 3

def username
  @username
end

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
# File 'lib/github-backup/backup.rb', line 25

def execute
  backup_all
rescue Octokit::Unauthorized
  puts "Github API authentication failed."
  puts "Please add a [github] section to your ~/.gitconfig"
  puts "  See: http://github.com/guides/tell-git-your-user-name-and-email-address"
  puts "Or, use the arguments to authenticate with your username and API token."
end