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
-
#lesson ⇒ Object
readonly
Returns the value of attribute lesson.
-
#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.
14 15 16 17 18 19 |
# File 'lib/commit-live/lesson/open.rb', line 14 def initialize() if File.exists?("#{HOME_DIR}/.ga-config") @rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace] end @lesson = CommitLive::Current.new end |
Instance Attribute Details
#lesson ⇒ Object (readonly)
Returns the value of attribute lesson.
10 11 12 |
# File 'lib/commit-live/lesson/open.rb', line 10 def lesson @lesson end |
#lessonName ⇒ Object (readonly)
Returns the value of attribute lessonName.
10 11 12 |
# File 'lib/commit-live/lesson/open.rb', line 10 def lessonName @lessonName end |
#rootDir ⇒ Object (readonly)
Returns the value of attribute rootDir.
10 11 12 |
# File 'lib/commit-live/lesson/open.rb', line 10 def rootDir @rootDir end |
Instance Method Details
#cdToLesson ⇒ Object
83 84 85 86 87 88 |
# File 'lib/commit-live/lesson/open.rb', line 83 def cdToLesson puts "Opening lesson..." Dir.chdir("#{rootDir}/#{lessonName}") puts "Done." exec("#{ENV['SHELL']} -l") end |
#change_grp_owner ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/commit-live/lesson/open.rb', line 74 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/commit-live/lesson/open.rb', line 57 def cloneCurrentLesson puts "Cloning lesson..." begin Timeout::timeout(15) do cloneUrl = lesson.getAttr('forked_repo') Git.clone("[email protected]:#{cloneUrl}.git", 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/commit-live/lesson/open.rb', line 39 def forkCurrentLesson puts "Forking lesson..." github = CommitLive::Github.new() begin Timeout::timeout(15) do lessonRepo = lesson.getAttr('github_repo') 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commit-live/lesson/open.rb', line 21 def openALesson(*puzzle_name) # get currently active lesson puts "Getting current lesson..." lesson.getCurrentLesson(puzzle_name) @lessonName = lesson.getAttr('lesson_name') if !File.exists?("#{rootDir}/#{lessonName}") # fork lesson repo via github api forkCurrentLesson # clone forked lesson into machine cloneCurrentLesson # change group owner change_grp_owner end # install dependencies # cd into it and invoke bash cdToLesson end |