Class: ET::Lesson
- Inherits:
-
Object
- Object
- ET::Lesson
- Defined in:
- lib/et/lesson.rb
Instance Attribute Summary collapse
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
Instance Method Summary collapse
- #archive! ⇒ Object
- #dir ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(cwd) ⇒ Lesson
constructor
A new instance of Lesson.
- #slug ⇒ Object
Constructor Details
#initialize(cwd) ⇒ Lesson
Returns a new instance of Lesson.
9 10 11 |
# File 'lib/et/lesson.rb', line 9 def initialize(cwd) @cwd = cwd end |
Instance Attribute Details
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
7 8 9 |
# File 'lib/et/lesson.rb', line 7 def cwd @cwd end |
Instance Method Details
#archive! ⇒ Object
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 39 40 |
# File 'lib/et/lesson.rb', line 13 def archive! if exists? filepath = random_archive_path File.open(filepath, "wb") do |file| Zlib::GzipWriter.wrap(file) do |gz| Gem::Package::TarWriter.new(gz) do |tar| ET::SubmissionFileList.new(dir).each do |file| relative_path = file absolute_path = File.join(dir, file) if FileTest.directory?(absolute_path) tar.mkdir(relative_path, 0755) else file_contents = File.read(absolute_path) tar.add_file_simple("./" + relative_path, 0555, file_contents.bytesize) do |io| io.write(file_contents) end end end end end end filepath else nil end end |
#dir ⇒ Object
42 43 44 |
# File 'lib/et/lesson.rb', line 42 def dir @dir ||= find_lesson_dir(cwd) end |
#exists? ⇒ Boolean
50 51 52 |
# File 'lib/et/lesson.rb', line 50 def exists? !dir.nil? end |
#slug ⇒ Object
46 47 48 |
# File 'lib/et/lesson.rb', line 46 def slug File.basename(dir) end |