Class: Cocina::Generator::Generator

Inherits:
Thor
  • Object
show all
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

Class Method Details

.source_rootObject



12
13
14
# File 'lib/cocina/generator/generator.rb', line 12

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cocina/generator/generator.rb', line 17

def generate
  clean_output

  # rubocop:disable Style/HashEachMethods
  # This is not a Hash
  schemas.keys.each do |schema_name|
    schema = schema_for(schema_name)
    generate_for(schema) if schema
  end
  # rubocop:enable Style/HashEachMethods

  generate_vocab
end

#generate_schema(schema_name) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cocina/generator/generator.rb', line 32

def generate_schema(schema_name)
  schema = schema_for(schema_name)
  raise 'Cannot generate' if schema.nil?

  FileUtils.mkdir_p(options[:output])

  generate_for(schema)
end

#generate_vocabObject



42
43
44
45
46
47
48
49
# File 'lib/cocina/generator/generator.rb', line 42

def generate_vocab
  vocab = Vocab.new(schemas)
  filepath = "#{options[:output]}/#{vocab.filename}"
  FileUtils.rm_f(filepath)

  create_file filepath, vocab.generate
  run("rubocop -a #{filepath}")
end