Class: GovukSchemas::Schema
- Inherits:
-
Object
- Object
- GovukSchemas::Schema
- Defined in:
- lib/govuk_schemas/schema.rb
Class Method Summary (collapse)
-
+ (Object) all(schema_type: '*')
Return all schemas in a hash, keyed by schema name.
-
+ (Object) find(schema_name, schema_type:)
Find a schema by name.
-
+ (Object) random_schema(schema_type:)
Return a random schema of a certain type.
Class Method Details
+ (Object) all(schema_type: '*')
Return all schemas in a hash, keyed by schema name
16 17 18 19 20 21 22 |
# File 'lib/govuk_schemas/schema.rb', line 16 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 |
+ (Object) find(schema_name, schema_type:)
Find a schema by name
7 8 9 10 11 |
# File 'lib/govuk_schemas/schema.rb', line 7 def self.find(schema_name, schema_type:) schema_type = "publisher_v2" if schema_type == "publisher" file_path = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/#{schema_name}/#{schema_type}/schema.json" JSON.parse(File.read(file_path)) end |
+ (Object) random_schema(schema_type:)
Return a random schema of a certain type
27 28 29 |
# File 'lib/govuk_schemas/schema.rb', line 27 def self.random_schema(schema_type:) all(schema_type: schema_type).values.sample end |