Class: ET::Lesson

Inherits:
Object
  • Object
show all
Defined in:
lib/et/lesson.rb

Direct Known Subclasses

Challenge, Exercise

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cwd) ⇒ Lesson

Returns a new instance of Lesson.



8
9
10
# File 'lib/et/lesson.rb', line 8

def initialize(cwd)
  @cwd = cwd
end

Instance Attribute Details

#cwdObject (readonly)

Returns the value of attribute cwd.



6
7
8
# File 'lib/et/lesson.rb', line 6

def cwd
  @cwd
end

Instance Method Details

#archive!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/et/lesson.rb', line 12

def archive!
  if exists?
    filepath = random_archive_path

    cmd = "tar zcf #{filepath} -C #{dir}"

    ignored_files.each do |file|
      cmd += " --exclude='#{file}'"
    end

    cmd += " ."

    if system(cmd)
      filepath
    else
      nil
    end
  else
    nil
  end
end

#dirObject



34
35
36
# File 'lib/et/lesson.rb', line 34

def dir
  @dir ||= find_lesson_dir(cwd)
end

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/et/lesson.rb', line 42

def exists?
  !dir.nil?
end

#ignored_filesObject



46
47
48
# File 'lib/et/lesson.rb', line 46

def ignored_files
  (config["ignore"] || []) + [".lesson.yml"]
end

#slugObject



38
39
40
# File 'lib/et/lesson.rb', line 38

def slug
  File.basename(dir)
end