Class: JsonSchemaDocs::Generator

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/json-schema-docs/generator.rb

Constant Summary

Constants included from Helpers

Helpers::SLUGIFY_PRETTY_REGEXP

Instance Attribute Summary collapse

Attributes included from Helpers

#templates

Instance Method Summary collapse

Methods included from Helpers

#include, #slugify

Constructor Details

#initialize(parsed_schema, options) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json-schema-docs/generator.rb', line 10

def initialize(parsed_schema, options)
  @parsed_schema = parsed_schema
  @options = options

  i(endpoint object).each do |sym|
    if !File.exist?(@options[:templates][sym])
      raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found"
    end
    instance_variable_set("@json_schema_#{sym}_template", ERB.new(File.read(@options[:templates][sym]), nil, '-'))
  end
end

Instance Attribute Details

#parsed_schemaObject

Returns the value of attribute parsed_schema.



8
9
10
# File 'lib/json-schema-docs/generator.rb', line 8

def parsed_schema
  @parsed_schema
end

Instance Method Details

#generateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/json-schema-docs/generator.rb', line 22

def generate
  FileUtils.rm_rf(@options[:output_dir]) if @options[:delete_output]

  @parsed_schema.each_pair do |resource, schemata|
    i(endpoint object).each do |type|
      contents = render(type, resource, schemata)
      write_file(type, resource, contents)

      contents = render(type, resource, schemata)
      write_file(type, resource, contents)
    end
  end
end