class Unixoid::Controller
Public Class Methods
debug()
click to toggle source
# 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
run()
click to toggle source
# 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
Private Class Methods
attempted(results)
click to toggle source
# 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!()
click to toggle source
# 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_file()
click to toggle source
# File lib/unixoid/controller.rb, line 39 def create_history_file Runner.run('cp ~/.bash_history commands.txt') end
final_result(results)
click to toggle source
# File lib/unixoid/controller.rb, line 43 def final_result(results) puts render_results(results) end
get_config(git)
click to toggle source
# 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!()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
run_challenge()
click to toggle source
# File lib/unixoid/controller.rb, line 34 def run_challenge challenge = Challenge.run_specs ChallengeResult.new(challenge) end