publishing_platform_schemas 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +27 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/publishing_platform_schemas/schema.rb +50 -0
- data/lib/publishing_platform_schemas/version.rb +5 -0
- data/lib/publishing_platform_schemas.rb +18 -0
- data/publishing_platform_schemas.gemspec +24 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88231446d780966954fa7df80621e314cb2d885e187402b7d68e8ee2d10513e2
|
4
|
+
data.tar.gz: 33fd84d51fab3235f9f5089153939493a7c4a66eca9553a8288e77e55bd3cd74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d0f1ebc0dc699816e80c3fadf1a88678f5f44b9c0963b8e2c3e797adb908bc1f3f9a5a96ea4a6982cbe5bb2ff83daf8c3b9c57f56ea1ace47f1f51fd172b74f
|
7
|
+
data.tar.gz: 6671a6f2e8996641695e7b48b76f658180e9945986e81a90ed32c6f92e0352a0e25ac26daac258e1edb7136b51023a5e48e99010d7b930265275db653191718c
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '3.1.2'
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v3
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
- name: Run the default task
|
27
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Publishing Platform
|
4
|
+
Copyright (c) 2016 Crown Copyright (Government Digital Service)
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "publishing_platform_schemas"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module PublishingPlatformSchemas
|
2
|
+
class Schema
|
3
|
+
# Find a schema by name
|
4
|
+
#
|
5
|
+
# @param schema [Hash] Type => Name of the schema/format:
|
6
|
+
# @example
|
7
|
+
#
|
8
|
+
# PublishingPlatformSchemas::Schema.find(links_schema: "detailed_guide")
|
9
|
+
# PublishingPlatformSchemas::Schema.find(frontend_schema: "detailed_guide")
|
10
|
+
# PublishingPlatformSchemas::Schema.find(publisher_schema: "detailed_guide")
|
11
|
+
# PublishingPlatformSchemas::Schema.find(notification_schema: "detailed_guide")
|
12
|
+
# @return [Hash] the JSON schema as a hash
|
13
|
+
def self.find(schema)
|
14
|
+
file_path = "#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/#{location_for_schema_name(schema)}"
|
15
|
+
JSON.parse(File.read(file_path))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return all schemas in a hash, keyed by schema name
|
19
|
+
#
|
20
|
+
# @param schema_type [String] The type: frontend, publisher, notification or links
|
21
|
+
# @return [Array<Hash>] List of JSON schemas as hashes
|
22
|
+
def self.all(schema_type: "*")
|
23
|
+
schema_type = "publisher" if schema_type == "publisher"
|
24
|
+
Dir.glob("#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/*/#{schema_type}/*.json").each_with_object({}) do |file_path, hash|
|
25
|
+
hash[file_path] = JSON.parse(File.read(file_path))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return all schema names
|
30
|
+
#
|
31
|
+
# @return [Array] all the schema names
|
32
|
+
def self.schema_names
|
33
|
+
Dir.glob("#{PublishingPlatformSchemas.content_schema_dir}/dist/formats/*").map do |directory|
|
34
|
+
File.basename(directory)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
def self.location_for_schema_name(schema)
|
40
|
+
type, schema_name = schema.to_a.flatten
|
41
|
+
{
|
42
|
+
links_schema: "#{schema_name}/publisher/links.json",
|
43
|
+
frontend_schema: "#{schema_name}/frontend/schema.json",
|
44
|
+
publisher_schema: "#{schema_name}/publisher/schema.json",
|
45
|
+
}[type]
|
46
|
+
end
|
47
|
+
|
48
|
+
private_class_method :location_for_schema_name
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "publishing_platform_schemas/version"
|
4
|
+
require_relative "publishing_platform_schemas/schema"
|
5
|
+
|
6
|
+
module PublishingPlatformSchemas
|
7
|
+
def self.content_schema_dir=(path_to_schemas)
|
8
|
+
@content_schema_dir = path_to_schemas
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.content_schema_dir
|
12
|
+
@content_schema_dir ||= ENV.fetch("PUBLISHING_PLATFORM_CONTENT_SCHEMAS_PATH", "../publishing-api/content_schemas")
|
13
|
+
end
|
14
|
+
|
15
|
+
# @private
|
16
|
+
class InvalidContentGenerated < RuntimeError
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/publishing_platform_schemas/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "publishing_platform_schemas"
|
7
|
+
spec.version = PublishingPlatformSchemas::VERSION
|
8
|
+
spec.authors = ["Publishing Platform"]
|
9
|
+
|
10
|
+
spec.summary = "Gem to work with the Publishing Platform content schemas"
|
11
|
+
spec.description = "Gem to work with the Publishing Platform content schemas"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = ">= 3.0"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = %w[lib]
|
19
|
+
|
20
|
+
# This should be kept in sync with the json-schema version of publishing-api.
|
21
|
+
spec.add_dependency "json-schema", ">= 2.8", "< 4.4"
|
22
|
+
|
23
|
+
spec.add_development_dependency "publishing_platform_rubocop"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: publishing_platform_schemas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Publishing Platform
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json-schema
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.4'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.4'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: publishing_platform_rubocop
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Gem to work with the Publishing Platform content schemas
|
48
|
+
email:
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- ".github/workflows/main.yml"
|
54
|
+
- ".gitignore"
|
55
|
+
- ".rspec"
|
56
|
+
- ".rubocop.yml"
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- bin/console
|
62
|
+
- bin/setup
|
63
|
+
- lib/publishing_platform_schemas.rb
|
64
|
+
- lib/publishing_platform_schemas/schema.rb
|
65
|
+
- lib/publishing_platform_schemas/version.rb
|
66
|
+
- publishing_platform_schemas.gemspec
|
67
|
+
homepage:
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '3.0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.3.7
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Gem to work with the Publishing Platform content schemas
|
90
|
+
test_files: []
|