govuk_schemas 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/govuk_schemas/example.rb +25 -0
- data/lib/govuk_schemas/random_example.rb +15 -5
- data/lib/govuk_schemas/schema.rb +9 -0
- data/lib/govuk_schemas/version.rb +1 -1
- data/lib/govuk_schemas.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6896c57c2532adcb41b53a7299bc0199aee11e
|
4
|
+
data.tar.gz: 8aae891ff22402cff6c858b33490edaaaf326a7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb53487240a352345f504c932aee0b4895ae5aa8fb71aa91709563983fa3a6c0a06767009f8798dc126952655d865e4cff39ab1a242cba294e05d0b19ed97ad1
|
7
|
+
data.tar.gz: dd87037cb8ea2887b1397ecf55ccdbe45654067b4d834c3a854c7cab36eb9cc54260d64b0e43a31d6abdc302e47bdcfcbe507952722aaac6fbfa8ec979b77fb9
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module GovukSchemas
|
2
|
+
class Example
|
3
|
+
# Find all examples for a schema
|
4
|
+
#
|
5
|
+
# @param schema_name [String] like "detailed_guide", "policy" or "publication"
|
6
|
+
# @return [Array] array of example content items
|
7
|
+
def self.find_all(schema_name)
|
8
|
+
Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/formats/#{schema_name}/frontend/examples/*.json").map do |filename|
|
9
|
+
json = File.read(filename)
|
10
|
+
JSON.parse(json)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Find an example by name
|
15
|
+
#
|
16
|
+
# @param schema_name [String] like "detailed_guide", "policy" or "publication"
|
17
|
+
# @param example_name [String] the name of the example JSON file
|
18
|
+
# @return [Hash] the example content item
|
19
|
+
def self.find(schema_name, example_name:)
|
20
|
+
path = "/formats/#{schema_name}/frontend/examples/#{example_name}.json"
|
21
|
+
json = File.read("#{GovukSchemas::CONTENT_SCHEMA_DIR}#{path}")
|
22
|
+
JSON.parse(json)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -65,15 +65,25 @@ module GovukSchemas
|
|
65
65
|
# @param [Hash] hash The hash to merge the random content with
|
66
66
|
# @return [Hash] A content item
|
67
67
|
# @raise [GovukSchemas::InvalidContentGenerated]
|
68
|
-
def merge_and_validate(
|
69
|
-
|
70
|
-
|
68
|
+
def merge_and_validate(user_defined_values)
|
69
|
+
random_payload = @random_generator.payload
|
70
|
+
item_merged_with_user_input = random_payload.merge(Utils.stringify_keys(user_defined_values))
|
71
71
|
|
72
|
+
errors = validation_errors_for(item_merged_with_user_input)
|
72
73
|
if errors.any?
|
73
|
-
|
74
|
+
|
75
|
+
errors_on_random_payload = validation_errors_for(random_payload)
|
76
|
+
if errors_on_random_payload.any?
|
77
|
+
# The original item was invalid when it was generated, so it's not
|
78
|
+
# the users fault.
|
79
|
+
raise InvalidContentGenerated, error_message(random_payload, errors)
|
80
|
+
else
|
81
|
+
# The random item was valid, but it was merged with something invalid.
|
82
|
+
raise InvalidContentGenerated, error_message_custom(item_merged_with_user_input, user_defined_values, errors)
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
|
-
|
86
|
+
item_merged_with_user_input
|
77
87
|
end
|
78
88
|
|
79
89
|
private
|
data/lib/govuk_schemas/schema.rb
CHANGED
@@ -35,6 +35,15 @@ module GovukSchemas
|
|
35
35
|
all(schema_type: schema_type).values.sample
|
36
36
|
end
|
37
37
|
|
38
|
+
# Return all schema names
|
39
|
+
#
|
40
|
+
# @return [Array] all the schema names
|
41
|
+
def self.schema_names
|
42
|
+
Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/*").map do |directory|
|
43
|
+
File.basename(directory)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
# @private
|
39
48
|
def self.location_for_schema_name(schema)
|
40
49
|
type, schema_name = schema.to_a.flatten
|
data/lib/govuk_schemas.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- jenkins-schema.sh
|
147
147
|
- jenkins.sh
|
148
148
|
- lib/govuk_schemas.rb
|
149
|
+
- lib/govuk_schemas/example.rb
|
149
150
|
- lib/govuk_schemas/random.rb
|
150
151
|
- lib/govuk_schemas/random_example.rb
|
151
152
|
- lib/govuk_schemas/random_item_generator.rb
|