learn-open 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b905fb5b63cd3300320ce1bfe26ee55d41e0e1f5
4
- data.tar.gz: ce5f7440a90510f44c42390b71a1dc63790508e5
3
+ metadata.gz: 069ee8a90603867e8bb20af71a1ac6ba25d6ad41
4
+ data.tar.gz: aae6a5eb1ece18870d5e5abc3c4317261eaa001a
5
5
  SHA512:
6
- metadata.gz: 65f9eae1a2f1c6c72d6ec80687175492ee0d4c23feb4f69f0eeed5c9162e092f214bf95c208b50462db59d8e1b65f7b7539849a318de3ed8b55b18fd5d2bdad6
7
- data.tar.gz: e13ce0aef3e66eb2fef830311f834cb20f621838f018c8e48e73c9be303588d957b191c6e91ab5f6fbb833ea23de67cf94087a4dc7a583b5c7d5dcc63102685d
6
+ metadata.gz: e463a05d8fb609afed614cf4ced00d4b6c73aa534f3d79730971b0dc28871283864cd4aa1efc136b32f51c01bf93fe8f5f666e1ade76fe37d9ed4a8e1384fbe0
7
+ data.tar.gz: 7fd09c77afcd23dd52f5004d6a15cecb0a54e811c6ea875abf22484228f265639797468d413899299a6783f5a0a37cde2a18d979e6b147ed518a0e83376c9bc4
data/bin/learn-open CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  require 'learn_open'
4
4
 
5
- lesson, editor_specified = LearnOpen::ArgumentParser.new(ARGV).execute
5
+ lesson, editor_specified, next_lesson = LearnOpen::ArgumentParser.new(ARGV).execute
6
6
 
7
- LearnOpen::Opener.run(lesson: lesson, editor_specified: editor_specified)
7
+ LearnOpen::Opener.run(lesson: lesson, editor_specified: editor_specified, get_next_lesson: next_lesson)
data/learn-open.gemspec CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency "netrc"
24
24
  spec.add_runtime_dependency "git"
25
- spec.add_runtime_dependency "learn-web", ">= 1.0.0"
25
+ spec.add_runtime_dependency "learn-web", ">= 1.0.1"
26
26
  end
@@ -14,20 +14,23 @@ module LearnOpen
14
14
  end
15
15
 
16
16
  lesson = nil
17
+ next_lesson = false
17
18
 
18
19
  configured_editor = !(editor_data.empty? || editor_data.nil?) ? editor_data : nil
19
20
  editor_specified = ARGV.detect {|arg| arg.start_with?('--editor=')}.match(/\-\-editor=(.+)/) || configured_editor
20
21
  open_after = !!editor_specified
21
22
 
22
- if !ARGV[0].start_with?('--editor=')
23
+ if !ARGV[0].start_with?('--editor=') && !ARGV[0].start_with?('--next')
23
24
  lesson = ARGV[0]
25
+ elsif ARGV[0].start_with?('--next')
26
+ next_lesson = true
24
27
  end
25
28
 
26
29
  if open_after
27
30
  editor_specified = editor_specified.is_a?(String) ? editor_specified : editor_specified[1]
28
31
  end
29
32
 
30
- [lesson, editor_specified]
33
+ [lesson, editor_specified, next_lesson]
31
34
  end
32
35
  end
33
36
  end
@@ -1,20 +1,21 @@
1
1
  module LearnOpen
2
2
  class Opener
3
- attr_reader :editor, :client, :lessons_dir, :file_path
3
+ attr_reader :editor, :client, :lessons_dir, :file_path, :get_next_lesson
4
4
  attr_accessor :lesson, :repo_dir, :lesson_is_lab, :lesson_id
5
5
 
6
- def self.run(lesson:, editor_specified:)
7
- new(lesson, editor_specified).run
6
+ def self.run(lesson:, editor_specified:, get_next_lesson:)
7
+ new(lesson, editor_specified, get_next_lesson).run
8
8
  end
9
9
 
10
- def initialize(lesson, editor)
10
+ def initialize(lesson, editor, get_next_lesson)
11
11
  _login, token = Netrc.read['learn-config']
12
12
  @client = LearnWeb::Client.new(token: token)
13
13
 
14
- @lesson = lesson
15
- @editor = editor
16
- @lessons_dir = YAML.load(File.read(File.expand_path('~/.learn-config')))[:learn_directory]
17
- @file_path = File.expand_path('~/.learn-open-tmp')
14
+ @lesson = lesson
15
+ @editor = editor
16
+ @get_next_lesson = get_next_lesson
17
+ @lessons_dir = YAML.load(File.read(File.expand_path('~/.learn-config')))[:learn_directory]
18
+ @file_path = File.expand_path('~/.learn-open-tmp')
18
19
  end
19
20
 
20
21
  def run
@@ -47,11 +48,16 @@ module LearnOpen
47
48
  def set_lesson
48
49
  File.write(file_path, 'Getting lesson...')
49
50
 
50
- if !lesson
51
+ if !lesson && !get_next_lesson
51
52
  puts "Getting current lesson..."
52
53
  self.lesson = get_current_lesson_forked_repo
53
54
  self.lesson_is_lab = current_lesson.lab
54
55
  self.lesson_id = current_lesson.id
56
+ elsif !lesson && get_next_lesson
57
+ puts "Getting next lesson..."
58
+ self.lesson = get_next_lesson_forked_repo
59
+ self.lesson_is_lab = next_lesson.lab
60
+ self.lesson_id = next_lesson.id
55
61
  else
56
62
  puts "Looking for lesson..."
57
63
  self.lesson = ensure_correct_lesson.repo_slug
@@ -66,6 +72,10 @@ module LearnOpen
66
72
  @current_lesson ||= client.current_lesson
67
73
  end
68
74
 
75
+ def next_lesson
76
+ @next_lesson ||= client.next_lesson
77
+ end
78
+
69
79
  def get_current_lesson_forked_repo(retries=3)
70
80
  begin
71
81
  Timeout::timeout(15) do
@@ -82,6 +92,22 @@ module LearnOpen
82
92
  end
83
93
  end
84
94
 
95
+ def get_next_lesson_forked_repo(retries=3)
96
+ begin
97
+ Timeout::timeout(15) do
98
+ next_lesson.forked_repo
99
+ end
100
+ rescue Timeout::Error
101
+ if retries > 0
102
+ puts "There was a problem getting your next lesson from Learn. Retrying..."
103
+ get_next_lesson_forked_repo(retries-1)
104
+ else
105
+ puts "There seems to be a problem connecting to Learn. Please try again."
106
+ exit
107
+ end
108
+ end
109
+ end
110
+
85
111
  def ensure_correct_lesson
86
112
  correct_lesson
87
113
  end
@@ -155,10 +181,19 @@ module LearnOpen
155
181
  end
156
182
 
157
183
  def ios_lesson?
158
- languages = YAML.load(File.read("#{lessons_dir}/#{repo_dir}/.learn"))['languages']
159
- ios_lang = languages.any? {|l| ['objc', 'swift'].include?(l)}
184
+ begin
185
+ languages = YAML.load(File.read("#{lessons_dir}/#{repo_dir}/.learn"))['languages']
186
+ ios_lang = languages.any? {|l| ['objc', 'swift'].include?(l)}
160
187
 
161
- ios_lang || xcodeproj_file? || xcworkspace_file?
188
+ ios_lang || xcodeproj_file? || xcworkspace_file?
189
+ rescue Psych::SyntaxError
190
+ if xcodeproj_file? || xcworkspace_file?
191
+ true
192
+ else
193
+ puts "There seems to be a problem with this lesson. Please submit a bug report to bugs@learn.co. If you'd like to work on your next lesson, type: learn next"
194
+ exit
195
+ end
196
+ end
162
197
  end
163
198
 
164
199
  def open_ios_lesson
@@ -1,3 +1,3 @@
1
1
  module LearnOpen
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn-open
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flatiron School
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.0.0
75
+ version: 1.0.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.0.0
82
+ version: 1.0.1
83
83
  description:
84
84
  email:
85
85
  - learn@flatironschool.com