Class: Belajar::Terminal::Solutions

Inherits:
Thor
  • Object
show all
Includes:
Output
Defined in:
lib/belajar/terminal/solutions.rb

Instance Method Summary collapse

Instance Method Details

#open(course_name = '') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/belajar/terminal/solutions.rb', line 10

def open(course_name = '')
  path = File.join(Belajar.config.solutions_path, course_name)

  unless Dir.exist?(path)
    text = [
      "The course directory \"#{File.basename(path)}\" is not available in",
      "\"#{File.dirname(path)}\".\n",
      'Hint:',
      'Run "belajar scaffold" to create empty solution files for all courses.'
    ]
    say_warning text.join("\n")

    unless Loading::Courses.load(Belajar.config.courses_path).empty?
      Terminal::Courses.new.list
    end

    return
  end

  if OS.windows?
    system "explorer '#{path}'"
  elsif OS.mac?
    system "open '#{path}'"
  elsif OS.linux?
    system "xdg-open '#{path}'"
  end
rescue ConfigurationError => e
  say_warning e.message
end