Class: Cocina::Generator::Generator
- Inherits:
-
Thor
- Object
- Thor
- Cocina::Generator::Generator
- Includes:
- Thor::Actions
- Defined in:
- lib/cocina/generator/generator.rb
Overview
Class for generating Cocina models from openapi.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_descriptive_docs ⇒ Object
- #generate_schema(schema_name) ⇒ Object
- #generate_vocab ⇒ Object
Class Method Details
.source_root ⇒ Object
14 15 16 |
# File 'lib/cocina/generator/generator.rb', line 14 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#generate ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cocina/generator/generator.rb', line 19 def generate clean_output filepaths = schemas.keys.filter_map do |schema_name| schema = schema_for(schema_name) generate_for(schema) if schema end %w[DRO Collection AdminPolicy].each do |schema_name| schema = schema_for(schema_name, lite: true) filepaths << generate_for(schema) end auto_format(filepaths) generate_vocab generate_descriptive_docs end |
#generate_descriptive_docs ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cocina/generator/generator.rb', line 54 def generate_descriptive_docs markdown = YAML.load_file('description_types.yml').map do |field, types| header_markdown = field_markdown_from(field) types_markdown = types_markdown_from(types) <<~MARKDOWN #{'#' * (field.count('.') + 1)} #{header_markdown} _Path: #{field}.type_ #{types_markdown} MARKDOWN end.join remove_file 'docs/description_types.md' create_file 'docs/description_types.md', markdown end |
#generate_schema(schema_name) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/cocina/generator/generator.rb', line 38 def generate_schema(schema_name) schema = schema_for(schema_name) raise 'Cannot generate' if schema.nil? FileUtils.mkdir_p([:output]) filepath = generate_for(schema) auto_format(filepath) end |