Class: PublishingPlatformSchemas::Schema
- Inherits:
-
Object
- Object
- PublishingPlatformSchemas::Schema
- Defined in:
- lib/publishing_platform_schemas/schema.rb
Class Method Summary collapse
-
.all(schema_type: "*") ⇒ Array<Hash>
Return all schemas in a hash, keyed by schema name.
-
.find(schema) ⇒ Hash
Find a schema by name.
-
.schema_names ⇒ Array
Return all schema names.
Class Method Details
.all(schema_type: "*") ⇒ Array<Hash>
Return all schemas in a hash, keyed by schema name
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
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_names ⇒ Array
Return all 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 |