Class: LearnOpen::Opener

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_open/opener.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lesson, editor) ⇒ Opener

Returns a new instance of Opener.



10
11
12
13
14
15
16
17
18
# File 'lib/learn_open/opener.rb', line 10

def initialize(lesson, editor)
  , token = Netrc.read['learn-config']
  @client       = LearnWeb::Client.new(token: token)

  @lesson       = lesson
  @editor       = editor
  @lessons_dir  = YAML.load(File.read(File.expand_path('~/.learn-config')))[:learn_directory]
  @file_path    = File.expand_path('~/.learn-open-tmp')
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def client
  @client
end

#editorObject (readonly)

Returns the value of attribute editor.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def editor
  @editor
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def file_path
  @file_path
end

#lessonObject

Returns the value of attribute lesson.



4
5
6
# File 'lib/learn_open/opener.rb', line 4

def lesson
  @lesson
end

#lesson_idObject

Returns the value of attribute lesson_id.



4
5
6
# File 'lib/learn_open/opener.rb', line 4

def lesson_id
  @lesson_id
end

#lesson_is_labObject

Returns the value of attribute lesson_is_lab.



4
5
6
# File 'lib/learn_open/opener.rb', line 4

def lesson_is_lab
  @lesson_is_lab
end

#lessons_dirObject (readonly)

Returns the value of attribute lessons_dir.



3
4
5
# File 'lib/learn_open/opener.rb', line 3

def lessons_dir
  @lessons_dir
end

#repo_dirObject

Returns the value of attribute repo_dir.



4
5
6
# File 'lib/learn_open/opener.rb', line 4

def repo_dir
  @repo_dir
end

Class Method Details

.run(lesson:, editor_specified:) ⇒ Object



6
7
8
# File 'lib/learn_open/opener.rb', line 6

def self.run(lesson:, editor_specified:)
  new(lesson, editor_specified).run
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/learn_open/opener.rb', line 20

def run
  setup_tmp_file

  set_lesson

  if lesson_is_readme?
    open_readme
  else
    fork_repo
    clone_repo
    bundle_install
    open_with_editor
    cd_to_lesson
  end

  cleanup_tmp_file
end