Class: Nachos::Main

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Github
Defined in:
lib/nachos/main.rb

Constant Summary

Constants included from Github

Github::GIT_CONFIG, Github::LGHCONF

Instance Attribute Summary collapse

Attributes included from Github

#client

Instance Method Summary collapse

Methods included from Github

#github_summary, #github_token, #github_user, #watched

Constructor Details

#initialize(cli) ⇒ Main

Returns a new instance of Main.



9
10
11
12
# File 'lib/nachos/main.rb', line 9

def initialize(cli)
  @cli = cli
  @config = Nachos::Config.new
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



7
8
9
# File 'lib/nachos/main.rb', line 7

def cli
  @cli
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/nachos/main.rb', line 7

def config
  @config
end

Instance Method Details

#chdir(dir) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/nachos/main.rb', line 26

def chdir(dir)
  shell.say_status :inside, dir
  if dry_run?
    yield
  else
    FileUtils.mkdir_p(dir) unless File.exist?(dir)
    FileUtils.cd(dir) { yield }
  end
end

#Hub(args) ⇒ Object



56
57
58
# File 'lib/nachos/main.rb', line 56

def Hub(args)
  Hub::Runner.new(*args.split(' '))
end

#infoObject



14
15
16
17
18
# File 'lib/nachos/main.rb', line 14

def info
%[You are running Nachos #{Nachos::VERSION} as #{github_user}.
#{github_summary}
Current configuration: #{config.display_config}]
end

#repo_exists?(repo) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/nachos/main.rb', line 52

def repo_exists?(repo)
  repo_path(repo).directory?
end

#repo_path(repo) ⇒ Object



48
49
50
# File 'lib/nachos/main.rb', line 48

def repo_path(repo)
  Pathname(config.repo_root.join("#{repo.owner}-#{repo.name}"))
end

#run(cmd) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/nachos/main.rb', line 60

def run(cmd)
  if dry_run?
    shell.say cmd
  else
    system cmd
  end
end

#syncObject



20
21
22
23
24
# File 'lib/nachos/main.rb', line 20

def sync
  chdir config.repo_root do
    watched.each { |repo| sync_repo(repo) }
  end
end

#sync_repo(repo) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nachos/main.rb', line 36

def sync_repo(repo)
  git_url = repo.url.gsub("https", "git")
  path = repo_path(repo)
  if repo_exists?(repo)
    chdir(path) do
      run Hub("fetch").command
    end
  else
    run Hub("clone #{git_url} #{repo.owner}-#{repo.name}").command
  end
end