Class: Unixoid::Controller

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

Class Method Summary collapse

Class Method Details

.attempted(results) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/unixoid/controller.rb', line 71

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



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

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

.create_history_fileObject



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

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



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

def final_result(results)
  puts render_results(results)
end

.get_config(git) ⇒ Object



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

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

.push_to_github(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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)
  get_config(git) unless git.configured?

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

.render_results(results) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/unixoid/controller.rb', line 59

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



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

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