Module: Mumukit::Sync::Store::Github::Schema

Defined in:
lib/mumukit/sync/store/github/schema.rb

Overview

Schema definition explanation

* name: the name of the field
* kind: the type of the field: metadata, special, file or transient.
   * metadata fields are those that are small and fit into the metadata.yml when exported to git
   * special fields are those are essentials and not part of any file, like the id or name when exported to git
   * transient fields are not exported to git
   * file fields are large fields that are exported to git within their own file.
* reverse: the name of the field in the model. By default, it is assumed to be the same of name, but
  can be overridden with this option
* default: the default value of the field
* extension: the file extension. It only applies to file kinds. It can be a plain extension or one of the following
  special extensions:
    * test: the extension of the test framework
    * code: the normal extension for the language

Defined Under Namespace

Classes: Field

Instance Method Summary collapse

Instance Method Details

#defaultsObject



19
20
21
# File 'lib/mumukit/sync/store/github/schema.rb', line 19

def defaults
  fields.map { |it| [it.reverse_name, it.default] }.to_h.compact
end

#fieldsObject



43
44
45
# File 'lib/mumukit/sync/store/github/schema.rb', line 43

def fields
  @field ||= fields_schema.map { |it| new_field(it) }
end

#file_fieldsObject



31
32
33
# File 'lib/mumukit/sync/store/github/schema.rb', line 31

def file_fields
  fields.select { |it| it.kind == :file }
end

#file_patternsObject



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

def file_patterns
  file_fields.map(&:get_file_pattern) + fixed_file_patterns
end

#fixed_file_patternsObject



39
40
41
# File 'lib/mumukit/sync/store/github/schema.rb', line 39

def fixed_file_patterns
  []
end

#metadata_fieldsObject



23
24
25
# File 'lib/mumukit/sync/store/github/schema.rb', line 23

def 
  fields.select { |it| it.kind == :metadata }
end

#nameObject



61
62
63
# File 'lib/mumukit/sync/store/github/schema.rb', line 61

def name
  with { |it| it&.dig(:name) }
end

#simple_fieldsObject



27
28
29
# File 'lib/mumukit/sync/store/github/schema.rb', line 27

def simple_fields
  fields.select { |it| [:special, :file].include? it.kind }
end

#slice(json) ⇒ Object



47
48
49
# File 'lib/mumukit/sync/store/github/schema.rb', line 47

def slice(json)
  json.slice(*fields.map(&:reverse_name))
end

#with(&block) ⇒ Object



65
66
67
# File 'lib/mumukit/sync/store/github/schema.rb', line 65

def with(&block)
  struct to: block, from: proc { |it| File.read(it) }
end

#yaml_hashObject



51
52
53
54
# File 'lib/mumukit/sync/store/github/schema.rb', line 51

def yaml_hash
  struct to: proc(&:to_yaml),
         from: proc { |path| YAML.load_file(path) }
end

#yaml_list(key) ⇒ Object



56
57
58
59
# File 'lib/mumukit/sync/store/github/schema.rb', line 56

def yaml_list(key)
  struct to: proc { |it| {key => it.map(&:stringify_keys)}.to_yaml },
         from: proc { |path| YAML.load_file(path).try { |it| it[key] } }
end