learn-doctor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e2668c052b700cd3553430dd1e17576aeaeea06f
4
+ data.tar.gz: 38668dc800bd9a17ac5dcce0fe1858581a14974b
5
+ SHA512:
6
+ metadata.gz: 3988baba9fbda7bea8d2eee8fb1959a79d9297b226bfb261a9b4370c3ca275167f9d0736e58daa6a6086db555daa5d5e3030de168436514eb1c93a88babc272e
7
+ data.tar.gz: 60ce2fb547b3f2cdf2176e70817f915bb9319ec757cfb428aa8bd2ac9b906d203c9f8535dcb35531dd334b7fd4df191487475080a0aab36360ec9ac01ad38ce6
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in learn-doctor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Flatiron School
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # learn-doctor
2
+
3
+ Check and fix your environment based on Learn.co's defaults.
4
+
5
+ ## Installation
6
+
7
+ Install with:
8
+
9
+ ```
10
+ $ gem install learn-doctor
11
+ ```
12
+
13
+ Alternatively, add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'learn-doctor'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ Run:
26
+
27
+ ```
28
+ $ learn-doctor
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/flatiron-labs/learn-doctor/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/learn-doctor ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'learn_doctor'
4
+
5
+ # To prevent weird errors when random command line args are passed in
6
+ KNOWN_COMMANDS = []
7
+
8
+ ARGV.map! do |arg|
9
+ KNOWN_COMMANDS.include?(arg) ? arg : nil
10
+ end.compact!
11
+
12
+ LearnDoctor::HealthCheck.diagnose
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'learn_doctor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "learn-doctor"
8
+ spec.version = LearnDoctor::VERSION
9
+ spec.authors = ["Flatiron School"]
10
+ spec.email = ["learn@flatironschool.com"]
11
+ spec.summary = %q{Check your environment setup against Learn.co's defaults}
12
+ spec.homepage = "https://learn.co"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib", "bin"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_runtime_dependency "netrc"
24
+ spec.add_runtime_dependency "faraday", "~> 0.9"
25
+ spec.add_runtime_dependency "colorize"
26
+ spec.add_runtime_dependency "learn-web", ">= 1.0.5"
27
+ end
@@ -0,0 +1,48 @@
1
+ module LearnDoctor
2
+ class HealthCheck
3
+ class File
4
+ attr_reader :step, :check_or_install, :conn
5
+ attr_accessor :file
6
+
7
+ def initialize(step, check_or_install)
8
+ @step = step
9
+ @check_or_install = check_or_install
10
+ @conn = Faraday.new
11
+
12
+ prepare_file!
13
+
14
+ return self
15
+ end
16
+
17
+ def unlink!
18
+ self.file.unlink
19
+ end
20
+
21
+ def path
22
+ file.path
23
+ end
24
+
25
+ private
26
+
27
+ def prepare_file!
28
+ create_file!
29
+ write_to_file!
30
+ make_executable!
31
+ end
32
+
33
+ def create_file!
34
+ self.file = Tempfile.new(step[:title])
35
+ end
36
+
37
+ def write_to_file!
38
+ response = conn.get(step[check_or_install])
39
+ file.write(response.body)
40
+ file.rewind
41
+ end
42
+
43
+ def make_executable!
44
+ FileUtils.chmod('+x', file.path)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,45 @@
1
+ module LearnDoctor
2
+ class HealthCheck
3
+ class StepChecker
4
+ attr_reader :step, :title
5
+ attr_accessor :file, :result
6
+
7
+ def initialize(step)
8
+ @step = step
9
+ @title = step[:title]
10
+ end
11
+
12
+ def execute
13
+ set_file
14
+ run_check_for_step
15
+ print_result
16
+ unlink_file!
17
+
18
+ self
19
+ end
20
+
21
+ private
22
+
23
+ def set_file
24
+ self.file = LearnDoctor::HealthCheck::File.new(step, :check)
25
+ end
26
+
27
+ def run_check_for_step
28
+ print "#{title}..."
29
+ self.result = Open3.popen3('bash', file.path)[1].read.strip.to_i
30
+ end
31
+
32
+ def print_result
33
+ if result == 1
34
+ puts 'ok'
35
+ else
36
+ puts 'error'.red
37
+ end
38
+ end
39
+
40
+ def unlink_file!
41
+ file.unlink!
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module LearnDoctor
2
+ class HealthCheck
3
+ class StepInstaller
4
+ attr_reader :step, :title
5
+ attr_accessor :file, :result
6
+
7
+ def initialize(step)
8
+ @step = step
9
+ @title = step[:title]
10
+ end
11
+
12
+ def execute
13
+ set_file
14
+ run_install_for_step
15
+ print_result
16
+ unlink_file!
17
+
18
+ self
19
+ end
20
+
21
+ private
22
+
23
+ def set_file
24
+ self.file = LearnDoctor::HealthCheck::File.new(step, :install)
25
+ end
26
+
27
+ def run_install_for_step
28
+ print "Installing #{title}..."
29
+ self.result = Open3.popen3('bash', file.path)[1].read.strip
30
+ end
31
+
32
+ def print_result
33
+ if result.match(/Done/)
34
+ puts 'done'.green
35
+ else
36
+ puts 'error'.red
37
+ end
38
+ end
39
+
40
+ def unlink_file!
41
+ file.unlink!
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,98 @@
1
+ require 'learn_doctor/health_check/file'
2
+ require 'learn_doctor/health_check/step_checker'
3
+ require 'learn_doctor/health_check/step_installer'
4
+
5
+ module LearnDoctor
6
+ class HealthCheck
7
+ attr_reader :client, :passed_steps, :failed_steps
8
+ attr_accessor :setup_step_list
9
+
10
+ def self.diagnose
11
+ new.diagnose
12
+ end
13
+
14
+ def initialize
15
+ _login, token = Netrc.read['learn-config']
16
+ @client = LearnWeb::Client.new(token: token)
17
+ @passed_steps = []
18
+ @failed_steps = []
19
+ end
20
+
21
+ def diagnose
22
+ get_setup_step_list!
23
+ run_checks!
24
+ install_failures!
25
+ end
26
+
27
+ private
28
+
29
+ def get_setup_step_list!
30
+ puts 'Getting latest environment environment setup data from Learn...'
31
+ self.setup_step_list = client.environment_setup_list
32
+ end
33
+
34
+ def run_checks!
35
+ setup_step_list.steps.each do |key, step|
36
+ step_check = LearnDoctor::HealthCheck::StepChecker.new(step).execute
37
+
38
+ case step_check.result
39
+ when 1
40
+ self.passed_steps << step
41
+ when 0
42
+ self.failed_steps << step
43
+ end
44
+ end
45
+ end
46
+
47
+ def install_failures!
48
+ if failed_steps.any?
49
+ response = prompt_to_fix
50
+
51
+ if response
52
+ run_installations!
53
+ recheck_failures
54
+ else
55
+ exit
56
+ end
57
+ end
58
+ end
59
+
60
+ def prompt_to_fix
61
+ failed_checks = failed_steps.map{|s| s[:title] }.join(', ')
62
+
63
+ puts "It looks like the following things aren't configured correctly: #{failed_checks}"
64
+ print "Automatically try to fix? [yN]: "
65
+
66
+ response = gets.chomp.downcase
67
+
68
+ ['yes', 'y'].include?(response) ? true : false
69
+ end
70
+
71
+ def run_installations!
72
+ failed_steps.each do |step|
73
+ LearnDoctor::HealthCheck::StepInstaller.new(step).execute
74
+ end
75
+ end
76
+
77
+ def recheck_failures
78
+ puts "Rechecking environment..."
79
+ reinstallation_results = failed_steps.map do |step|
80
+ step_check = LearnDoctor::HealthCheck::StepChecker.new(step).execute
81
+
82
+ case step_check.result
83
+ when 1
84
+ nil
85
+ else
86
+ step[:title]
87
+ end
88
+ end.compact
89
+
90
+ if reinstallation_results.any?
91
+ puts "Unfortunately, there were problems trying to fix the following: #{reinstallation_results.join(', ')}"
92
+ puts "Please send an email to support@learn.co to get help."
93
+ else
94
+ exit
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ module LearnDoctor
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'netrc'
2
+ require 'faraday'
3
+ require 'colorize'
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+ require 'open3'
7
+ require 'learn_web'
8
+
9
+ require 'learn_doctor/version'
10
+ require 'learn_doctor/health_check'
11
+
12
+ module LearnDoctor
13
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: learn-doctor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Flatiron School
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: netrc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: learn-web
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.5
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.5
97
+ description:
98
+ email:
99
+ - learn@flatironschool.com
100
+ executables:
101
+ - learn-doctor
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/learn-doctor
111
+ - learn-doctor.gemspec
112
+ - lib/learn_doctor.rb
113
+ - lib/learn_doctor/health_check.rb
114
+ - lib/learn_doctor/health_check/file.rb
115
+ - lib/learn_doctor/health_check/step_checker.rb
116
+ - lib/learn_doctor/health_check/step_installer.rb
117
+ - lib/learn_doctor/version.rb
118
+ homepage: https://learn.co
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ - bin
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Check your environment setup against Learn.co's defaults
143
+ test_files: []