Class: Unixoid::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/unixoid/controller.rb

Class Method Summary collapse

Class Method Details

.attempted(results) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/unixoid/controller.rb', line 77

def attempted(results)
  %{
Almost there! Feel free to try again and re-submit

The following answers need to be corrected:

    #{results.failures.join(", ")}
  }
end

.auth_fail!Object



60
61
62
63
# File 'lib/unixoid/controller.rb', line 60

def auth_fail!
  puts 'Incorrect login details. Please run unixoid-challenge again'.red
  exit 1
end

.create_history_fileObject



39
40
41
# File 'lib/unixoid/controller.rb', line 39

def create_history_file
  Runner.run('cp ~/.bash_history commands.txt')
end

.debugObject



11
12
13
14
15
# File 'lib/unixoid/controller.rb', line 11

def self.debug
  puts "Submitting your history to Makers Academy so we can help you debug..."
  create_history_file
  push_to_github('commands.txt')
end

.final_result(results) ⇒ Object



43
44
45
# File 'lib/unixoid/controller.rb', line 43

def final_result(results)
  puts render_results(results)
end

.get_config(git) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/unixoid/controller.rb', line 47

def get_config(git)
  puts 'Please enter your full name:'
  name = gets.chomp
  puts 'Please enter your e-mail address:'
  email = gets.chomp
  git.configure(name, email)
end

.git_fail!Object



55
56
57
58
# File 'lib/unixoid/controller.rb', line 55

def git_fail!
  puts 'Git is not installed - please follow the instructions at https://help.github.com/articles/set-up-git and then try again'.red
  exit 1
end

.push_to_github(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/unixoid/controller.rb', line 21

def push_to_github(file)
  github = Github.create_repo
  auth_fail! unless github.authenticated?

  git = Git.new(github)
  git_fail! unless git.installed?
  get_config(git) unless git.configured?

  puts "Submitting..."
  git.submit(file)
  puts "Submitted!"
end

.render_results(results) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/unixoid/controller.rb', line 65

def render_results(results)
  case results.status
  when :complete
    'Congratulations, you have successfully completed the Unixoid Challenge!'.green
  when :attempted
    attempted(results).yellow
  when :unattempted
    puts 'Looks like you have not tried the challenge. Give it a go and then re-submit'.red
    exit 0
  end
end

.runObject



4
5
6
7
8
9
# File 'lib/unixoid/controller.rb', line 4

def self.run
  results = run_challenge
  puts "Submitting your results to Makers Academy..."
  push_to_github(Challenge::RESULTS_FILE)
  final_result(results)
end

.run_challengeObject



34
35
36
37
# File 'lib/unixoid/controller.rb', line 34

def run_challenge
  challenge = Challenge.run_specs
  ChallengeResult.new(challenge)
end