lib/learn_open/opener.rb in learn-open-1.0.2 vs lib/learn_open/opener.rb in learn-open-1.0.3

- old
+ new

@@ -1,8 +1,8 @@ module LearnOpen class Opener - attr_reader :editor, :client, :lessons_dir + attr_reader :editor, :client, :lessons_dir, :file_path attr_accessor :lesson, :repo_dir, :lesson_is_lab, :lesson_id def self.run(lesson:, editor_specified:) new(lesson, editor_specified).run end @@ -12,13 +12,16 @@ @client = LearnWeb::Client.new(token: token) @lesson = lesson @editor = editor @lessons_dir = YAML.load(File.read(File.expand_path('~/.learn-config')))[:learn_directory] + @file_path = File.expand_path('~/.learn-open-tmp') end def run + setup_tmp_file + set_lesson if lesson_is_readme? open_readme else @@ -26,15 +29,28 @@ clone_repo bundle_install open_with_editor cd_to_lesson end + + cleanup_tmp_file end private + def setup_tmp_file + FileUtils.touch(file_path) + File.write(file_path, '') + end + + def cleanup_tmp_file + File.write(file_path, 'Done.') + end + def set_lesson + File.write(file_path, 'Getting lesson...') + if !lesson puts "Getting current lesson..." self.lesson = get_current_lesson_forked_repo self.lesson_is_lab = current_lesson.lab self.lesson_id = current_lesson.id @@ -88,10 +104,11 @@ end end def fork_repo(retries=3) if !repo_exists? + File.write(file_path, 'Forking repository...') puts "Forking lesson..." begin Timeout::timeout(15) do client.fork_repo(repo_name: repo_dir) end @@ -107,9 +124,10 @@ end end def clone_repo(retries=3) if !repo_exists? + File.write(file_path, 'Cloning to your machine...') puts "Cloning lesson..." begin Timeout::timeout(15) do Git.clone("git@github.com:#{lesson}.git", repo_dir, path: lessons_dir) end