lib/learn_open/opener.rb in learn-open-1.2.5 vs lib/learn_open/opener.rb in learn-open-1.2.6
- old
+ new
@@ -27,34 +27,19 @@
warn_if_necessary
if lesson_is_readme?
open_readme
else
- fork_repo
- clone_repo
- bundle_install
- npm_install
- open_with_editor
- cd_to_lesson
+ git_tasks
+ file_tasks
+ dependency_tasks
+ completion_tasks
end
end
def repo_exists?
- cloned_labs = "#{HOME_DIR}/.cloned_labs"
- if File.exists?(cloned_labs)
- puts "Loading..."
- syncing_done = "#{HOME_DIR}/.syncing_started"
- sleep 1 until File.exists?(syncing_done)
- if File.readlines(cloned_labs).grep(/#{repo_dir}/).any?
- sleep 1 until File.exists?("#{lessons_dir}/#{repo_dir}")
- true
- else
- false
- end
- else
- File.exists?("#{lessons_dir}/#{repo_dir}")
- end
+ File.exists?("#{lessons_dir}/#{repo_dir}/.git")
end
private
def ping_fork_completion(retries=3)
@@ -268,11 +253,11 @@
def open_with_editor
if ios_lesson?
open_ios_lesson
elsif editor
- system("cd #{lessons_dir}/#{repo_dir} && #{editor} .")
+ system("#{editor} .")
end
end
def ios_lesson?
begin
@@ -333,30 +318,27 @@
end
def cd_to_lesson
puts "Opening lesson..."
Dir.chdir("#{lessons_dir}/#{repo_dir}")
- cleanup_tmp_file
- puts "Done."
- exec("#{ENV['SHELL']} -l")
end
def bundle_install
if !ios_lesson? && File.exists?("#{lessons_dir}/#{repo_dir}/Gemfile")
puts "Bundling..."
- system("cd #{lessons_dir}/#{repo_dir} && bundle install > /dev/null 2>&1")
+ system("bundle install > /dev/null 2>&1")
end
end
def npm_install
if !ios_lesson? && File.exists?("#{lessons_dir}/#{repo_dir}/package.json")
puts 'Installing dependencies...'
if ide_environment?
- system("cd #{lessons_dir}/#{repo_dir} && yarn install --no-lockfile")
+ system("yarn install --no-lockfile")
else
- system("cd #{lessons_dir}/#{repo_dir} && npm install")
+ system("npm install")
end
end
end
def lesson_is_readme?
@@ -401,8 +383,29 @@
!!RUBY_PLATFORM.match(/darwin/)
end
def ide_environment?
ENV['IDE_CONTAINER'] == "true"
+ end
+
+ def git_tasks
+ fork_repo
+ clone_repo
+ end
+
+ def file_tasks
+ cd_to_lesson
+ open_with_editor
+ end
+
+ def dependency_tasks
+ bundle_install
+ npm_install
+ end
+
+ def completion_tasks
+ cleanup_tmp_file
+ puts "Done."
+ exec("#{ENV['SHELL']} -l")
end
end
end