Class: LearnOpen::Environments::BaseEnvironment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BaseEnvironment

Returns a new instance of BaseEnvironment.



7
8
9
10
11
12
13
# File 'lib/learn_open/environments/base_environment.rb', line 7

def initialize(options={})
  @io = options.fetch(:io) { LearnOpen.default_io }
  @environment_vars = options.fetch(:environment_vars) { LearnOpen.environment_vars }
  @system_adapter = options.fetch(:system_adapter) { LearnOpen.system_adapter }
  @logger = options.fetch(:logger) { LearnOpen.logger }
  @options = options
end

Instance Attribute Details

#environment_varsObject (readonly)

Returns the value of attribute environment_vars.



5
6
7
# File 'lib/learn_open/environments/base_environment.rb', line 5

def environment_vars
  @environment_vars
end

#ioObject (readonly)

Returns the value of attribute io.



5
6
7
# File 'lib/learn_open/environments/base_environment.rb', line 5

def io
  @io
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/learn_open/environments/base_environment.rb', line 5

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/learn_open/environments/base_environment.rb', line 5

def options
  @options
end

#system_adapterObject (readonly)

Returns the value of attribute system_adapter.



5
6
7
# File 'lib/learn_open/environments/base_environment.rb', line 5

def system_adapter
  @system_adapter
end

Instance Method Details

#download_lesson(lesson, location) ⇒ Object



46
47
48
# File 'lib/learn_open/environments/base_environment.rb', line 46

def download_lesson(lesson, location)
  LessonDownloader.call(lesson, location, self, options)
end

#install_dependencies(lesson, location) ⇒ Object



42
43
44
# File 'lib/learn_open/environments/base_environment.rb', line 42

def install_dependencies(lesson, location)
  DependencyInstallers.run_installers(lesson, location, self, options)
end

#managed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/learn_open/environments/base_environment.rb', line 15

def managed?
  false
end

#notify_of_completionObject



64
65
66
67
# File 'lib/learn_open/environments/base_environment.rb', line 64

def notify_of_completion
  logger.log("Done.")
  io.puts "Done."
end

#open_editor(lesson, location, editor) ⇒ Object



50
51
52
53
54
# File 'lib/learn_open/environments/base_environment.rb', line 50

def open_editor(lesson, location, editor)
  io.puts "Opening lesson..."
  system_adapter.change_context_directory(lesson.to_path)
  system_adapter.open_editor(editor, path: ".")
end

#open_jupyter_lab(_lesson, _location, _editor, _clone_only) ⇒ Object



19
20
21
# File 'lib/learn_open/environments/base_environment.rb', line 19

def open_jupyter_lab(_lesson, _location, _editor, _clone_only)
  :noop
end

#open_lab(lesson, location, editor, clone_only) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/learn_open/environments/base_environment.rb', line 23

def open_lab(lesson, location, editor, clone_only)
  case lesson
  when LearnOpen::Lessons::IosLesson
    io.puts "You need to be on a Mac to work on iOS lessons."
  else
    case download_lesson(lesson, location)
    when :ok, :noop
      open_editor(lesson, location, editor) unless clone_only
      install_dependencies(lesson, location)
      notify_of_completion
      open_shell unless clone_only
    when :ssh_unauthenticated
      io.puts 'Failed to obtain an SSH connection!'
    else
      raise LearnOpen::Environments::UnknownLessonDownloadError
    end
  end
end

#open_shellObject



60
61
62
# File 'lib/learn_open/environments/base_environment.rb', line 60

def open_shell
  system_adapter.(environment_vars['SHELL'])
end

#start_file_backup(lesson, location) ⇒ Object



56
57
58
# File 'lib/learn_open/environments/base_environment.rb', line 56

def start_file_backup(lesson, location)
  FileBackupStarter.call(lesson, location, options)
end