Class: LearnOpen::Opener
- Inherits:
-
Object
- Object
- LearnOpen::Opener
- Defined in:
- lib/learn_open/opener.rb
Constant Summary collapse
- HOME_DIR =
File.("~")
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#dot_learn ⇒ Object
Returns the value of attribute dot_learn.
-
#editor ⇒ Object
readonly
Returns the value of attribute editor.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#get_next_lesson ⇒ Object
readonly
Returns the value of attribute get_next_lesson.
-
#later_lesson ⇒ Object
Returns the value of attribute later_lesson.
-
#lesson ⇒ Object
Returns the value of attribute lesson.
-
#lesson_id ⇒ Object
Returns the value of attribute lesson_id.
-
#lesson_is_lab ⇒ Object
Returns the value of attribute lesson_is_lab.
-
#lessons_dir ⇒ Object
readonly
Returns the value of attribute lessons_dir.
-
#repo_dir ⇒ Object
Returns the value of attribute repo_dir.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(lesson, editor, get_next_lesson) ⇒ Opener
constructor
A new instance of Opener.
- #repo_exists? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(lesson, editor, get_next_lesson) ⇒ Opener
Returns a new instance of Opener.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/learn_open/opener.rb', line 11 def initialize(lesson, editor, get_next_lesson) _login, @token = Netrc.read['learn-config'] @client = LearnWeb::Client.new(token: @token) @lesson = lesson @editor = editor @get_next_lesson = get_next_lesson @lessons_dir = YAML.load(File.read("#{HOME_DIR}/.learn-config"))[:learn_directory] @file_path = "#{HOME_DIR}/.learn-open-tmp" end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def client @client end |
#dot_learn ⇒ Object
Returns the value of attribute dot_learn.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def dot_learn @dot_learn end |
#editor ⇒ Object (readonly)
Returns the value of attribute editor.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def editor @editor end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def file_path @file_path end |
#get_next_lesson ⇒ Object (readonly)
Returns the value of attribute get_next_lesson.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def get_next_lesson @get_next_lesson end |
#later_lesson ⇒ Object
Returns the value of attribute later_lesson.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def later_lesson @later_lesson end |
#lesson ⇒ Object
Returns the value of attribute lesson.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def lesson @lesson end |
#lesson_id ⇒ Object
Returns the value of attribute lesson_id.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def lesson_id @lesson_id end |
#lesson_is_lab ⇒ Object
Returns the value of attribute lesson_is_lab.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def lesson_is_lab @lesson_is_lab end |
#lessons_dir ⇒ Object (readonly)
Returns the value of attribute lessons_dir.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def lessons_dir @lessons_dir end |
#repo_dir ⇒ Object
Returns the value of attribute repo_dir.
5 6 7 |
# File 'lib/learn_open/opener.rb', line 5 def repo_dir @repo_dir end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/learn_open/opener.rb', line 4 def token @token end |
Class Method Details
.run(lesson:, editor_specified:, get_next_lesson:) ⇒ Object
7 8 9 |
# File 'lib/learn_open/opener.rb', line 7 def self.run(lesson:, editor_specified:, get_next_lesson:) new(lesson, editor_specified, get_next_lesson).run end |
Instance Method Details
#repo_exists? ⇒ Boolean
61 62 63 |
# File 'lib/learn_open/opener.rb', line 61 def repo_exists? File.exists?("#{lessons_dir}/#{repo_dir}/.git") end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/learn_open/opener.rb', line 22 def run setup_tmp_file set_lesson if ide_version_3? if self.repo_dir != ENV['LAB_NAME'] home_dir = "/home/#{ENV['CREATED_USER']}" File.open("#{home_dir}/.custom_commands.log", "a") do |f| f.puts %Q{{"command": "open_lab", "lab_name": "#{self.repo_dir}"}} end exit end end puts "Looking for lesson..." if jupyter_notebook_environment? git_tasks file_tasks restore_files watch_for_changes jupyter_pip_install completion_tasks else warn_if_necessary if lesson_is_readme? open_readme else git_tasks file_tasks setup_backup_if_needed dependency_tasks completion_tasks end end end |