comet 0.0.7 → 0.0.8
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 +4 -4
- data/bin/comet +2 -150
- data/lib/comet.rb +7 -4
- data/lib/comet/api.rb +17 -13
- data/lib/comet/exceptions.rb +3 -0
- data/lib/comet/kata.rb +50 -0
- data/lib/comet/runner.rb +149 -0
- data/lib/comet/tester.rb +27 -0
- data/lib/comet/version.rb +45 -1
- metadata +6 -3
- data/lib/comet/challenge.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49ebcc395830a1dc6cc0670c0d199a04e2fcd0bc
|
4
|
+
data.tar.gz: cfa6efb0f36fadf6531fe9ec992786ccdda26fb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3116fb988de10b2928da84610bc1dddc38d45e35befaf9798ed2fb92e8d347350b4c57dce645619b6b79f81dbc7d3610b2e48b80a13673ab8a584f614782dcc
|
7
|
+
data.tar.gz: 0b3281a3042f811813172cbc0c0a4455edbd7c7ebaa34834b3e08b8b86b282ef123f883c1813c61ce4c363a1aa63a5d849e7a1a8da832103b14bdcb62ef99f8a
|
data/bin/comet
CHANGED
@@ -1,152 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'gli'
|
3
|
-
require 'yaml'
|
4
|
-
require 'comet'
|
5
|
-
require 'helpers'
|
6
|
-
require 'openssl'
|
7
|
-
require 'shellwords'
|
8
|
-
|
9
|
-
include GLI::App
|
10
|
-
|
11
|
-
program_desc 'Test your Ruby skills! Download Ruby exercises and submit your solutions for grading.'
|
12
|
-
|
13
|
-
version Comet::VERSION
|
14
|
-
|
15
|
-
desc 'Initialize the current directory as a comet project directory'
|
16
|
-
skips_pre
|
17
|
-
command :init do |c|
|
18
|
-
c.action do |global_options, options, args|
|
19
|
-
answers = Comet::Init.find_config(Dir.pwd) || {}
|
20
|
-
|
21
|
-
['email', 'token', 'server'].each do |setting|
|
22
|
-
answers[setting] = prompt_for_setting(setting, answers)
|
23
|
-
end
|
24
|
-
|
25
|
-
Comet::Init.init_project_dir(Dir.pwd, answers)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
desc 'List the available challenges'
|
30
|
-
command :list do |c|
|
31
|
-
c.action do |global_options,options,args|
|
32
|
-
challenges = Comet::Challenge.list(@config)
|
33
|
-
|
34
|
-
if challenges.empty?
|
35
|
-
puts "No challenges available."
|
36
|
-
else
|
37
|
-
challenges.each do |challenge|
|
38
|
-
printf("(%4d) \e[34m%s\e[0m: %s (%s)\n",
|
39
|
-
challenge[:id],
|
40
|
-
challenge[:topic_name],
|
41
|
-
challenge[:name],
|
42
|
-
difficulty_to_string(challenge[:difficulty]))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'Download a challenge'
|
49
|
-
command :fetch do |c|
|
50
|
-
c.action do |global_options, options, args|
|
51
|
-
challenge_id = args.first
|
52
|
-
challenge = Comet::Challenge.find(@config, challenge_id)
|
53
|
-
directory = challenge.download
|
54
|
-
|
55
|
-
info_file = File.join(directory, '.kata')
|
56
|
-
info = YAML.load(File.read(info_file))
|
57
|
-
info['id'] = challenge_id.to_i
|
58
|
-
|
59
|
-
File.write(info_file, info.to_yaml)
|
60
|
-
|
61
|
-
puts "Downloaded kata to #{directory}."
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
desc 'Run test suite'
|
66
|
-
command :test do |c|
|
67
|
-
c.action do |global_options, options, args|
|
68
|
-
current_dir = Dir.pwd
|
69
|
-
info_file = File.join(current_dir, '.kata')
|
70
|
-
|
71
|
-
if File.exists?(info_file)
|
72
|
-
kata_info = YAML.load(File.read(info_file))
|
73
2
|
|
74
|
-
|
75
|
-
|
76
|
-
runner = 'ruby'
|
77
|
-
when 'rspec'
|
78
|
-
runner = 'rspec --color --fail-fast'
|
79
|
-
else
|
80
|
-
runner = 'ruby'
|
81
|
-
end
|
82
|
-
|
83
|
-
slug = File.basename(current_dir)
|
84
|
-
test_file = File.join(current_dir, 'test', "#{slug}_test.rb")
|
85
|
-
|
86
|
-
exec("#{runner} #{test_file}")
|
87
|
-
else
|
88
|
-
puts "Not a challenge directory."
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
desc 'Submit challenge'
|
94
|
-
command :submit do |c|
|
95
|
-
c.action do |global_options, options, args|
|
96
|
-
require 'rest_client'
|
97
|
-
require 'tmpdir'
|
98
|
-
|
99
|
-
current_dir = Dir.pwd
|
100
|
-
kata_file = File.join(current_dir, '.kata')
|
101
|
-
|
102
|
-
if File.exists?(kata_file)
|
103
|
-
kata_info = YAML.load(File.read(kata_file))
|
104
|
-
lib_dir = File.join(current_dir, 'lib')
|
105
|
-
slug = File.basename(current_dir)
|
106
|
-
|
107
|
-
Dir.mktmpdir do |tmpdir|
|
108
|
-
submission_file = File.join(tmpdir, 'submission.tar.gz')
|
109
|
-
if system("tar zcf #{Shellwords.escape(submission_file)} -C #{Shellwords.escape(lib_dir)} .")
|
110
|
-
payload = {
|
111
|
-
submission: {
|
112
|
-
challenge_id: kata_info['id'],
|
113
|
-
archive: File.new(submission_file)
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
headers = { 'Authorization' => "Token #{@config['token']}" }
|
118
|
-
|
119
|
-
RestClient.post("#{@config['server']}/api/v1/submissions.json", payload, headers)
|
120
|
-
|
121
|
-
puts "Submitted solution for #{slug}."
|
122
|
-
else
|
123
|
-
puts "Unable to create submission archive."
|
124
|
-
exit 1
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
else
|
129
|
-
puts "Not a kata directory."
|
130
|
-
exit 1
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
pre do |global,command,options,args|
|
136
|
-
@config = Comet::Init.find_config(Dir.pwd)
|
137
|
-
!@config.nil?
|
138
|
-
end
|
139
|
-
|
140
|
-
post do |global,command,options,args|
|
141
|
-
# Post logic here
|
142
|
-
# Use skips_post before a command to skip this
|
143
|
-
# block on that command only
|
144
|
-
end
|
145
|
-
|
146
|
-
on_error do |exception|
|
147
|
-
# Error logic here
|
148
|
-
# return false to skip default error handling
|
149
|
-
raise exception
|
150
|
-
end
|
151
|
-
|
152
|
-
exit run(ARGV)
|
3
|
+
require 'comet'
|
4
|
+
exit Comet::Runner.go(ARGV, Dir.pwd)
|
data/lib/comet.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
require 'comet/
|
2
|
-
require 'comet/
|
3
|
-
require 'comet/
|
4
|
-
require 'comet/
|
1
|
+
require 'comet/exceptions'
|
2
|
+
require 'comet/api'
|
3
|
+
require 'comet/kata'
|
4
|
+
require 'comet/version'
|
5
|
+
require 'comet/init'
|
6
|
+
require 'comet/tester'
|
7
|
+
require 'comet/runner'
|
data/lib/comet/api.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
+
require 'rest-client'
|
3
4
|
|
4
5
|
module Comet
|
5
6
|
class API
|
6
|
-
|
7
|
+
RUBYGEMS_URL = 'https://rubygems.org/api/v1/gems/comet.json'
|
8
|
+
|
9
|
+
def self.latest_gem_version
|
10
|
+
results = JSON.parse(RestClient.get(RUBYGEMS_URL))
|
11
|
+
results['version']
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_katas(config)
|
7
15
|
response = request_with_token("#{config['server']}/api/v1/challenges.json",
|
8
16
|
config['token'])
|
9
17
|
|
@@ -11,11 +19,11 @@ module Comet
|
|
11
19
|
results[:challenges]
|
12
20
|
end
|
13
21
|
|
14
|
-
def self.
|
22
|
+
def self.get_kata(config, id)
|
15
23
|
response = request_with_token("#{config['server']}/api/v1/challenges/#{id}.json",
|
16
24
|
config['token'])
|
17
25
|
|
18
|
-
if response.code ==
|
26
|
+
if response.code == 200
|
19
27
|
results = JSON.parse(response.body, symbolize_names: true)
|
20
28
|
results[:challenge]
|
21
29
|
else
|
@@ -39,7 +47,7 @@ module Comet
|
|
39
47
|
dest
|
40
48
|
end
|
41
49
|
|
42
|
-
def self.submit(config,
|
50
|
+
def self.submit(config, kata_id, file_path)
|
43
51
|
uri = URI("#{config['server']}/api/v1/submissions.json")
|
44
52
|
req = Net::HTTP::Post.new(uri)
|
45
53
|
|
@@ -49,7 +57,7 @@ module Comet
|
|
49
57
|
req['Authorization'] = "Token #{config['token']}"
|
50
58
|
|
51
59
|
req.set_form_data({
|
52
|
-
'submission[challenge_id]' =>
|
60
|
+
'submission[challenge_id]' => kata_id,
|
53
61
|
'submission[file_name]' => file_name,
|
54
62
|
'submission[body]' => body
|
55
63
|
})
|
@@ -62,15 +70,11 @@ module Comet
|
|
62
70
|
private
|
63
71
|
|
64
72
|
def self.request_with_token(url, token)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
70
|
-
http.request(request)
|
73
|
+
begin
|
74
|
+
RestClient.get(url, { 'Authorization' => "Token #{token}" })
|
75
|
+
rescue RestClient::Unauthorized => e
|
76
|
+
raise Comet::UnauthorizedError
|
71
77
|
end
|
72
|
-
|
73
|
-
response
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
data/lib/comet/kata.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
class Comet::Kata
|
4
|
+
attr_reader :id, :name, :slug, :download_link, :basedir
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@id = params[:id]
|
8
|
+
@name = params[:name]
|
9
|
+
@slug = params[:slug]
|
10
|
+
@download_link = params[:download_link]
|
11
|
+
@basedir = params[:basedir]
|
12
|
+
end
|
13
|
+
|
14
|
+
def download
|
15
|
+
archive = Comet::API.download_archive(download_link, File.join(basedir, "#{slug}.tar.gz"))
|
16
|
+
`tar zxf #{Shellwords.escape(archive)} -C #{Shellwords.escape(basedir)}`
|
17
|
+
File.delete(archive)
|
18
|
+
File.join(basedir, slug)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.list(config)
|
22
|
+
Comet::API.get_katas(config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find(config, id)
|
26
|
+
kata_info = Comet::API.get_kata(config, id)
|
27
|
+
|
28
|
+
if kata_info.nil?
|
29
|
+
raise ArgumentError.new("Could not find kata with id = #{id}")
|
30
|
+
else
|
31
|
+
Comet::Kata.new(kata_info.merge({ basedir: config['basedir'] }))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_kata_dir(dir)
|
36
|
+
kata_file = File.join(dir, '.kata')
|
37
|
+
|
38
|
+
if File.exists?(kata_file)
|
39
|
+
kata_file
|
40
|
+
else
|
41
|
+
parent_dir = File.dirname(dir)
|
42
|
+
|
43
|
+
if parent_dir != '/' && parent_dir != '.'
|
44
|
+
find_kata_dir(parent_dir)
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/comet/runner.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'gli'
|
2
|
+
require 'yaml'
|
3
|
+
require 'helpers'
|
4
|
+
require 'openssl'
|
5
|
+
require 'shellwords'
|
6
|
+
|
7
|
+
module Comet
|
8
|
+
class Runner
|
9
|
+
extend GLI::App
|
10
|
+
version Comet::VERSION
|
11
|
+
|
12
|
+
def self.go(args, cwd)
|
13
|
+
program_desc 'Test your Ruby skills! Download Ruby exercises and submit your solutions for grading.'
|
14
|
+
|
15
|
+
desc 'Initialize the current directory as a comet project directory'
|
16
|
+
skips_pre
|
17
|
+
command :init do |c|
|
18
|
+
c.action do |global_options, options, args|
|
19
|
+
answers = Comet::Init.find_config(cwd) || {}
|
20
|
+
|
21
|
+
['email', 'token', 'server'].each do |setting|
|
22
|
+
answers[setting] = prompt_for_setting(setting, answers)
|
23
|
+
end
|
24
|
+
|
25
|
+
Comet::Init.init_project_dir(cwd, answers)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'List the available katas'
|
30
|
+
command :list do |c|
|
31
|
+
c.action do |global_options,options,args|
|
32
|
+
katas = Comet::Kata.list(@config)
|
33
|
+
|
34
|
+
if katas.empty?
|
35
|
+
puts "No katas available."
|
36
|
+
else
|
37
|
+
katas.each do |kata|
|
38
|
+
printf("(%4d) \e[34m%s\e[0m: %s (%s)\n",
|
39
|
+
kata[:id],
|
40
|
+
kata[:topic_name],
|
41
|
+
kata[:name],
|
42
|
+
difficulty_to_string(kata[:difficulty]))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Download a kata'
|
49
|
+
command :fetch do |c|
|
50
|
+
c.action do |global_options, options, args|
|
51
|
+
kata_id = args.first
|
52
|
+
kata = Comet::Kata.find(@config, kata_id)
|
53
|
+
directory = kata.download
|
54
|
+
|
55
|
+
info_file = File.join(directory, '.kata')
|
56
|
+
info = YAML.load(File.read(info_file))
|
57
|
+
info['id'] = kata_id.to_i
|
58
|
+
|
59
|
+
File.write(info_file, info.to_yaml)
|
60
|
+
|
61
|
+
puts "Downloaded kata to #{directory}."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'Run test suite'
|
66
|
+
command :test do |c|
|
67
|
+
c.action do |global_options, options, args|
|
68
|
+
kata_file = Comet::Kata.find_kata_dir(cwd)
|
69
|
+
|
70
|
+
if !kata_file.nil?
|
71
|
+
Comet::Tester.run_test_suite(kata_file)
|
72
|
+
else
|
73
|
+
$stderr.puts "\e[31mNot a kata directory.\e[0m"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
desc 'Submit kata'
|
79
|
+
command :submit do |c|
|
80
|
+
c.action do |global_options, options, args|
|
81
|
+
require 'rest_client'
|
82
|
+
require 'tmpdir'
|
83
|
+
|
84
|
+
current_dir = cwd
|
85
|
+
kata_file = File.join(current_dir, '.kata')
|
86
|
+
|
87
|
+
if File.exists?(kata_file)
|
88
|
+
kata_info = YAML.load(File.read(kata_file))
|
89
|
+
lib_dir = File.join(current_dir, 'lib')
|
90
|
+
slug = File.basename(current_dir)
|
91
|
+
|
92
|
+
Dir.mktmpdir do |tmpdir|
|
93
|
+
submission_file = File.join(tmpdir, 'submission.tar.gz')
|
94
|
+
if system("tar zcf #{Shellwords.escape(submission_file)} -C #{Shellwords.escape(lib_dir)} .")
|
95
|
+
payload = {
|
96
|
+
submission: {
|
97
|
+
challenge_id: kata_info['id'],
|
98
|
+
archive: File.new(submission_file)
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
headers = { 'Authorization' => "Token #{@config['token']}" }
|
103
|
+
|
104
|
+
RestClient.post("#{@config['server']}/api/v1/submissions.json", payload, headers)
|
105
|
+
|
106
|
+
puts "Submitted solution for #{slug}."
|
107
|
+
else
|
108
|
+
puts "Unable to create submission archive."
|
109
|
+
exit 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
else
|
114
|
+
puts "Not a kata directory."
|
115
|
+
exit 1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
pre do |global,command,options,args|
|
121
|
+
# Only query for newer versions when running commands that makes
|
122
|
+
# network calls.
|
123
|
+
if [:submit, :fetch, :list].include?(command.name)
|
124
|
+
latest_version = Comet::API.latest_gem_version
|
125
|
+
if Comet::Version.is_more_recent(latest_version)
|
126
|
+
$stderr.puts "\e[33mNOTICE: An updated version of comet exists. " +
|
127
|
+
"Run `gem update comet` to upgrade.\e[0m"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
@config = Comet::Init.find_config(cwd)
|
132
|
+
!@config.nil?
|
133
|
+
end
|
134
|
+
|
135
|
+
on_error do |exception|
|
136
|
+
case exception
|
137
|
+
when Comet::UnauthorizedError
|
138
|
+
$stderr.puts "\e[31mERROR: Invalid credentials. " +
|
139
|
+
"Verify that the e-mail, token, and server are correctly " +
|
140
|
+
"configured in #{File.join(@config['basedir'], '.comet')}\e[0m"
|
141
|
+
else
|
142
|
+
raise exception
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
run(args)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/lib/comet/tester.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Comet::Tester
|
4
|
+
def self.run_test_suite(kata_file)
|
5
|
+
kata_info = YAML.load(File.read(kata_file))
|
6
|
+
runner = test_runner_command(kata_info['test_runner'])
|
7
|
+
|
8
|
+
kata_dir = File.dirname(kata_file)
|
9
|
+
slug = File.basename(kata_dir)
|
10
|
+
test_file = File.join(kata_dir, 'test', "#{slug}_test.rb")
|
11
|
+
|
12
|
+
Kernel.exec("#{runner} #{test_file}")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.test_runner_command(key)
|
18
|
+
case key
|
19
|
+
when 'ruby'
|
20
|
+
'ruby'
|
21
|
+
when 'rspec'
|
22
|
+
'rspec --color --fail-fast'
|
23
|
+
else
|
24
|
+
key
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/comet/version.rb
CHANGED
@@ -1,3 +1,47 @@
|
|
1
1
|
module Comet
|
2
|
-
|
2
|
+
class Version
|
3
|
+
def self.build(major, minor, patch)
|
4
|
+
"#{major}.#{minor}.#{patch}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.parse(string)
|
8
|
+
version_levels = string.split('.').map { |version| version.to_i }
|
9
|
+
[version_levels[0], version_levels[1], version_levels[2]]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.compare(version_a, version_b)
|
13
|
+
a_major, a_minor, a_patch = parse(version_a)
|
14
|
+
b_major, b_minor, b_patch = parse(version_b)
|
15
|
+
|
16
|
+
if a_major > b_major
|
17
|
+
1
|
18
|
+
elsif a_major < b_major
|
19
|
+
-1
|
20
|
+
else
|
21
|
+
if a_minor > b_minor
|
22
|
+
1
|
23
|
+
elsif a_minor < b_minor
|
24
|
+
-1
|
25
|
+
else
|
26
|
+
if a_patch > b_patch
|
27
|
+
1
|
28
|
+
elsif a_patch < b_patch
|
29
|
+
-1
|
30
|
+
else
|
31
|
+
0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.is_more_recent(other_version)
|
38
|
+
compare(VERSION, other_version) < 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
MAJOR_VERSION = 0
|
43
|
+
MINOR_VERSION = 0
|
44
|
+
PATCH_LEVEL = 8
|
45
|
+
|
46
|
+
VERSION = Version.build(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
3
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Sheehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -95,8 +95,11 @@ files:
|
|
95
95
|
- comet.rdoc
|
96
96
|
- lib/comet.rb
|
97
97
|
- lib/comet/api.rb
|
98
|
-
- lib/comet/
|
98
|
+
- lib/comet/exceptions.rb
|
99
99
|
- lib/comet/init.rb
|
100
|
+
- lib/comet/kata.rb
|
101
|
+
- lib/comet/runner.rb
|
102
|
+
- lib/comet/tester.rb
|
100
103
|
- lib/comet/version.rb
|
101
104
|
- lib/helpers.rb
|
102
105
|
homepage: http://www.launchacademy.com
|
data/lib/comet/challenge.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'shellwords'
|
2
|
-
|
3
|
-
class Comet::Challenge
|
4
|
-
attr_reader :id, :name, :slug, :download_link, :basedir
|
5
|
-
|
6
|
-
def initialize(params)
|
7
|
-
@id = params[:id]
|
8
|
-
@name = params[:name]
|
9
|
-
@slug = params[:slug]
|
10
|
-
@download_link = params[:download_link]
|
11
|
-
@basedir = params[:basedir]
|
12
|
-
end
|
13
|
-
|
14
|
-
def download
|
15
|
-
archive = Comet::API.download_archive(download_link, File.join(basedir, "#{slug}.tar.gz"))
|
16
|
-
`tar zxf #{Shellwords.escape(archive)} -C #{Shellwords.escape(basedir)}`
|
17
|
-
File.delete(archive)
|
18
|
-
File.join(basedir, slug)
|
19
|
-
end
|
20
|
-
|
21
|
-
class << self
|
22
|
-
def list(config)
|
23
|
-
Comet::API.get_challenges(config)
|
24
|
-
end
|
25
|
-
|
26
|
-
def find(config, id)
|
27
|
-
challenge_info = Comet::API.get_challenge(config, id)
|
28
|
-
|
29
|
-
if challenge_info.nil?
|
30
|
-
raise ArgumentError.new("Could not find challenge with id = #{id}")
|
31
|
-
else
|
32
|
-
Comet::Challenge.new(challenge_info.merge({ basedir: config['basedir'] }))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|