Class: Greyatom::Open
- Inherits:
-
Object
- Object
- Greyatom::Open
- Defined in:
- lib/greyatom/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
- #cloneCurrentLesson ⇒ Object
- #forkCurrentLesson ⇒ Object
-
#initialize ⇒ Open
constructor
A new instance of Open.
- #openALesson ⇒ Object
Constructor Details
#initialize ⇒ Open
Returns a new instance of Open.
14 15 16 17 18 19 |
# File 'lib/greyatom/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 = Greyatom::Current.new end |
Instance Attribute Details
#lesson ⇒ Object (readonly)
Returns the value of attribute lesson.
10 11 12 |
# File 'lib/greyatom/lesson/open.rb', line 10 def lesson @lesson end |
#lessonName ⇒ Object (readonly)
Returns the value of attribute lessonName.
10 11 12 |
# File 'lib/greyatom/lesson/open.rb', line 10 def lessonName @lessonName end |
#rootDir ⇒ Object (readonly)
Returns the value of attribute rootDir.
10 11 12 |
# File 'lib/greyatom/lesson/open.rb', line 10 def rootDir @rootDir end |
Instance Method Details
#cdToLesson ⇒ Object
72 73 74 75 76 77 |
# File 'lib/greyatom/lesson/open.rb', line 72 def cdToLesson puts "Opening lesson..." Dir.chdir("#{rootDir}/#{lessonName}") puts "Done." exec("#{ENV['SHELL']} -l") end |
#cloneCurrentLesson ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/greyatom/lesson/open.rb', line 55 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/greyatom/lesson/open.rb', line 37 def forkCurrentLesson puts "Forking lesson..." github = Greyatom::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 ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/greyatom/lesson/open.rb', line 21 def openALesson # get currently active lesson puts "Getting current lesson..." lesson.getCurrentLesson @lessonName = lesson.getAttr('lesson_name') if !File.exists?("#{rootDir}/#{lessonName}") # fork lesson repo via github api forkCurrentLesson # clone forked lesson into machine cloneCurrentLesson end # install dependencies # cd into it and invoke bash cdToLesson end |