Class: MirrorGithub::Base
- Inherits:
-
Object
- Object
- MirrorGithub::Base
- Defined in:
- lib/mirror_github/base.rb
Instance Method Summary collapse
- #config ⇒ Object
- #github_connection ⇒ Object
-
#initialize(args = nil) ⇒ Base
constructor
A new instance of Base.
-
#mirror(repository) ⇒ Object
Creates a new mirroir repository at the target directory (if necessary) and fetches any updates.
-
#mirror_all ⇒ Object
Backs up all repositories from the organization defined in the config.
- #parse_arguments(args) ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/mirror_github/base.rb', line 5 def initialize(args = nil) parse_arguments(args) end |
Instance Method Details
#config ⇒ Object
28 29 30 |
# File 'lib/mirror_github/base.rb', line 28 def config @config ||= Configuration.new end |
#github_connection ⇒ Object
32 33 34 |
# File 'lib/mirror_github/base.rb', line 32 def github_connection @github_connection ||= Github.new(config.username, config.password, config.org) end |
#mirror(repository) ⇒ Object
Creates a new mirroir repository at the target directory (if necessary) and fetches any updates.
22 23 24 25 26 |
# File 'lib/mirror_github/base.rb', line 22 def mirror(repository) git = Git.new(config.backup_directory, repository) git.create_mirror unless git.mirror_exists? git.update_mirror end |
#mirror_all ⇒ Object
Backs up all repositories from the organization defined in the config.
10 11 12 13 14 15 16 17 18 |
# File 'lib/mirror_github/base.rb', line 10 def mirror_all puts "Mirroring #{github_connection.repositories.size} repositories..." github_connection.repositories.each do |repo| puts "Beginning #{repo.name}" mirror repo puts "Finished #{repo.name}" puts "" end end |
#parse_arguments(args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mirror_github/base.rb', line 36 def parse_arguments(args) args.each do |arg| option, value = arg.split('=').map { |v| v.chomp.strip } next unless option && value case option when "--config-file" then Configuration.config_file_path = value when "--backup-dir" then config.backup_directory = value end end end |