Class: PublishingPlatformSchemas::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/publishing_platform_schemas/schema.rb

Class Method Summary collapse

Class Method Details

.all(schema_type: "*") ⇒ Array<Hash>

Return all schemas in a hash, keyed by schema name

Parameters:

  • schema_type (String) (defaults to: "*")

    The type: frontend, publisher, notification or links

Returns:

  • (Array<Hash>)

    List of JSON schemas as hashes



22
23
24
25
26
27
# File 'lib/publishing_platform_schemas/schema.rb', line 22

def self.all(schema_type: "*")
  schema_type = "publisher" if schema_type == "publisher"
  Dir.glob("#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/*/#{schema_type}/*.json").each_with_object({}) do |file_path, hash|
    hash[file_path] = JSON.parse(File.read(file_path))
  end
end

.find(schema) ⇒ Hash

Find a schema by name

Examples:


PublishingPlatformSchemas::Schema.find(links_schema: "detailed_guide")
PublishingPlatformSchemas::Schema.find(frontend_schema: "detailed_guide")
PublishingPlatformSchemas::Schema.find(publisher_schema: "detailed_guide")
PublishingPlatformSchemas::Schema.find(notification_schema: "detailed_guide")

Parameters:

  • schema (Hash)

    Type => Name of the schema/format:

Returns:

  • (Hash)

    the JSON schema as a hash



13
14
15
16
# File 'lib/publishing_platform_schemas/schema.rb', line 13

def self.find(schema)
  file_path = "#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/#{location_for_schema_name(schema)}"
  JSON.parse(File.read(file_path))
end

.schema_namesArray

Return all schema names

Returns:

  • (Array)

    all the schema names



32
33
34
35
36
# File 'lib/publishing_platform_schemas/schema.rb', line 32

def self.schema_names
  Dir.glob("#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/*").map do |directory|
    File.basename(directory)
  end
end