Class: GovukSchemas::Schema
- Inherits:
-
Object
- Object
- GovukSchemas::Schema
- Defined in:
- lib/govuk_schemas/schema.rb
Class Method Summary (collapse)
-
+ (Array<Hash>) all(schema_type: '*')
Return all schemas in a hash, keyed by schema name.
-
+ (Hash) find(schema)
Find a schema by name.
-
+ (Hash) random_schema(schema_type:)
Return a random schema of a certain type.
Class Method Details
+ (Array<Hash>) all(schema_type: '*')
Return all schemas in a hash, keyed by schema name
22 23 24 25 26 27 28 |
# File 'lib/govuk_schemas/schema.rb', line 22 def self.all(schema_type: '*') schema_type = "publisher_v2" if schema_type == "publisher" Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/*/#{schema_type}/*.json").reduce({}) do |hash, file_path| hash[file_path] = JSON.parse(File.read(file_path)) hash end end |
+ (Hash) find(schema)
Find a schema by name
13 14 15 16 |
# File 'lib/govuk_schemas/schema.rb', line 13 def self.find(schema) file_path = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/#{location_for_schema_name(schema)}" JSON.parse(File.read(file_path)) end |
+ (Hash) random_schema(schema_type:)
Return a random schema of a certain type
34 35 36 |
# File 'lib/govuk_schemas/schema.rb', line 34 def self.random_schema(schema_type:) all(schema_type: schema_type).values.sample end |