Class: CommitLive::Open
- Inherits:
-
Object
- Object
- CommitLive::Open
- Defined in:
- lib/commit-live/lesson/open.rb
Constant Summary collapse
- HOME_DIR =
File.("~")
Instance Attribute Summary collapse
-
#forkedRepo ⇒ Object
readonly
Returns the value of attribute forkedRepo.
-
#lesson ⇒ Object
readonly
Returns the value of attribute lesson.
-
#lesson_status ⇒ Object
readonly
Returns the value of attribute lesson_status.
-
#lessonName ⇒ Object
readonly
Returns the value of attribute lessonName.
-
#rootDir ⇒ Object
readonly
Returns the value of attribute rootDir.
Instance Method Summary collapse
- #cdToLesson ⇒ Object
- #change_grp_owner ⇒ Object
- #cloneCurrentLesson ⇒ Object
- #forkCurrentLesson ⇒ Object
-
#initialize ⇒ Open
constructor
A new instance of Open.
- #openALesson(*puzzle_name) ⇒ Object
Constructor Details
#initialize ⇒ Open
Returns a new instance of Open.
15 16 17 18 19 20 21 |
# File 'lib/commit-live/lesson/open.rb', line 15 def initialize() if File.exists?("#{HOME_DIR}/.ga-config") @rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace] end @lesson = CommitLive::Current.new @lesson_status = CommitLive::Status.new end |
Instance Attribute Details
#forkedRepo ⇒ Object (readonly)
Returns the value of attribute forkedRepo.
11 12 13 |
# File 'lib/commit-live/lesson/open.rb', line 11 def forkedRepo @forkedRepo end |
#lesson ⇒ Object (readonly)
Returns the value of attribute lesson.
11 12 13 |
# File 'lib/commit-live/lesson/open.rb', line 11 def lesson @lesson end |
#lesson_status ⇒ Object (readonly)
Returns the value of attribute lesson_status.
11 12 13 |
# File 'lib/commit-live/lesson/open.rb', line 11 def lesson_status @lesson_status end |
#lessonName ⇒ Object (readonly)
Returns the value of attribute lessonName.
11 12 13 |
# File 'lib/commit-live/lesson/open.rb', line 11 def lessonName @lessonName end |
#rootDir ⇒ Object (readonly)
Returns the value of attribute rootDir.
11 12 13 |
# File 'lib/commit-live/lesson/open.rb', line 11 def rootDir @rootDir end |
Instance Method Details
#cdToLesson ⇒ Object
89 90 91 92 93 94 |
# File 'lib/commit-live/lesson/open.rb', line 89 def cdToLesson puts "Opening lesson..." Dir.chdir("#{rootDir}/#{lessonName}") puts "Done." exec("#{ENV['SHELL']} -l") end |
#change_grp_owner ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/commit-live/lesson/open.rb', line 80 def change_grp_owner results = system("chgrp -R ubuntu #{rootDir}/#{lessonName}") if results puts "..." else puts "Couldn't change group ownership" end end |
#cloneCurrentLesson ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/commit-live/lesson/open.rb', line 64 def cloneCurrentLesson puts "Cloning lesson..." begin Timeout::timeout(15) do Git.clone(forkedRepo.ssh_url, lessonName, path: rootDir) end rescue Git::GitExecuteError => err puts "Error while cloning!" puts err exit rescue Timeout::Error puts "Cannot clone this lesson right now. Please try again." exit end end |
#forkCurrentLesson ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/commit-live/lesson/open.rb', line 45 def forkCurrentLesson puts "Forking lesson..." github = CommitLive::Github.new() begin Timeout::timeout(15) do lessonData = lesson.getAttr('data') lessonRepo = lessonData['chapters']['lessons']['repo_url'] @forkedRepo = github.client.fork(lessonRepo) end rescue Octokit::Error => err puts "Error while forking!" puts err exit rescue Timeout::Error puts "Please check your internet connection." exit end end |
#openALesson(*puzzle_name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/commit-live/lesson/open.rb', line 23 def openALesson(*puzzle_name) # get currently active lesson puts "Getting current lesson..." lesson.getCurrentLesson(puzzle_name) lessonData = lesson.getAttr('data') @lessonName = lessonData['chapters']['lessons']['title'] if !File.exists?("#{rootDir}/#{lessonName}") # fork lesson repo via github api forkCurrentLesson # clone forked lesson into machine cloneCurrentLesson # change group owner change_grp_owner # lesson forked API change puts 'Updating lesson status...' lesson_status.update('lesson_forked', lessonName) end # install dependencies # cd into it and invoke bash cdToLesson end |