Class: Mumukit::Sync::Store::Github::GuideWriter

Inherits:
Object
  • Object
show all
Includes:
WithSchema
Defined in:
lib/mumukit/sync/store/github/guide_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WithSchema

#build_fields_h, #exercise_schema, #guide_schema

Constructor Details

#initialize(dir) ⇒ GuideWriter

Returns a new instance of GuideWriter.



7
8
9
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 7

def initialize(dir)
  @dir = dir
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



5
6
7
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 5

def dir
  @dir
end

Instance Method Details

#format_id(guide, exercise) ⇒ Object



35
36
37
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 35

def format_id(guide, exercise)
  guide[:id_format] % exercise[:id]
end

#write_exercise!(guide, e) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 39

def write_exercise!(guide, e)
  dirname = File.join dir, to_fs_friendly_name("#{format_id(guide, e)}_#{e[:name]}")

  FileUtils.mkdir_p dirname

   dirname, exercise_schema, e
  write_file_fields! dirname, exercise_schema, e, (e[:language] || guide[:language])
end

#write_file_fields!(base_path, schema, element, language) ⇒ Object



11
12
13
14
15
16
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 11

def write_file_fields!(base_path, schema, element, language)
  schema.file_fields.each do |it|
    file_name = it.get_file_name(language)
    write_file! base_path, file_name, it.get_field_value(element) if it.field_value_present?(element)
  end
end

#write_guide!(guide) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 25

def write_guide!(guide)
  guide[:exercises].each do |e|
    write_exercise! guide, e
  end
  write_licenses!(guide)

   dir, guide_schema, guide
  write_file_fields! dir, guide_schema, guide, guide[:language]
end

#write_licenses!(guide) ⇒ Object



48
49
50
51
52
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 48

def write_licenses!(guide)
  write_file! dir, 'COPYRIGHT.txt', copyright_content(guide)
  write_file! dir, 'README.md', readme_content(guide)
  copy_file! 'LICENSE.txt'
end

#write_metadata_fields!(base_path, schema, e) ⇒ Object



18
19
20
21
22
23
# File 'lib/mumukit/sync/store/github/guide_writer.rb', line 18

def (base_path, schema, e)
   = schema..map do |field|
    [field.name.to_s, field.get_field_value(e)]
  end.to_h.compact.merge('name' => e[:name]).to_yaml
  write_file! base_path, 'meta.yml', 
end