Module: Generator::SchemaGenerator::ClassMethods

Defined in:
lib/generator/support/schema_generator.rb

Instance Method Summary collapse

Instance Method Details

#all_schemasObject

Get all schema instances (memoized)



31
32
33
34
# File 'lib/generator/support/schema_generator.rb', line 31

def all_schemas
  instance_variable_get("@all_#{schema_type}") ||
    instance_variable_set("@all_#{schema_type}", schema_files.map { |file| new(file) })
end

#cleanup!Object

Clean up generated files and directories for this schema type



23
24
25
26
27
28
# File 'lib/generator/support/schema_generator.rb', line 23

def cleanup!
  ["lib", "sig"].each do |base_dir|
    schemas_path = File.join(Config::BASE_PATH, base_dir, "peddler/#{schema_type}")
    FileUtils.rm_rf(schemas_path) if Dir.exist?(schemas_path)
  end
end

#filter_schema_files(files) ⇒ Object

Hook for subclasses to filter schema files (e.g., reject examples) Override in subclass if needed



44
45
46
# File 'lib/generator/support/schema_generator.rb', line 44

def filter_schema_files(files)
  files
end

#generateObject

Generate all schema files in parallel



17
18
19
20
# File 'lib/generator/support/schema_generator.rb', line 17

def generate
  cleanup!
  Parallel.each(all_schemas, &:generate)
end

#schema_filesObject

Find all schema files for this type



37
38
39
40
# File 'lib/generator/support/schema_generator.rb', line 37

def schema_files
  pattern = File.join(Config::BASE_PATH, "selling-partner-api-models/schemas/#{schema_type}/*.json")
  Dir.glob(pattern).then { |files| filter_schema_files(files) }
end

#schema_typeObject

Hook: schema type name (e.g., "notifications", "reports", "feeds") Must be implemented by including class

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/generator/support/schema_generator.rb', line 50

def schema_type
  raise NotImplementedError, "#{self} must implement .schema_type"
end