govuk_schemas 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +14 -28
- data/Rakefile +6 -0
- data/docs/GovukSchemas.html +120 -0
- data/docs/GovukSchemas/RandomExample.html +579 -0
- data/docs/GovukSchemas/Schema.html +420 -0
- data/docs/_index.html +140 -0
- data/docs/class_list.html +58 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +57 -0
- data/docs/css/style.css +339 -0
- data/docs/file.README.html +120 -0
- data/docs/file_list.html +60 -0
- data/docs/frames.html +26 -0
- data/docs/index.html +120 -0
- data/docs/js/app.js +219 -0
- data/docs/js/full_list.js +181 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +99 -0
- data/docs/top-level-namespace.html +112 -0
- data/govuk_schemas.gemspec +3 -2
- data/lib/govuk_schemas.rb +3 -0
- data/lib/govuk_schemas/random.rb +3 -2
- data/lib/govuk_schemas/random_example.rb +39 -6
- data/lib/govuk_schemas/random_item_generator.rb +14 -1
- data/lib/govuk_schemas/schema.rb +13 -3
- data/lib/govuk_schemas/utils.rb +16 -0
- data/lib/govuk_schemas/version.rb +2 -1
- metadata +39 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0284fbbf0aea21ee8b9dd454dc8934f9c9da9b0b
|
4
|
+
data.tar.gz: e0555905e01eeb2dada139cb1f43f4030d5bc6ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c4f413d705359a75802147e74a7cd2c58d122f8ae16d8dc464259ac63394f7260709f7c3fec1a8eff490f4552d31d8c63abfdb5b778522c38a1d21e6f8ed05a
|
7
|
+
data.tar.gz: d949094bfa6c8a7ac8894daa1a58a6fffee3520b193099c8742ccc3c20a5cb70f133919e1bed5f4cab692c49f4c307c7a3bd85c9a452733d4f09f7032bb4c71d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# 0.2.0
|
2
|
+
|
3
|
+
* Add a new regex for the new application validation in the schema
|
4
|
+
* Add documentation for the gem
|
5
|
+
* Fixes a problem with an infinite loop in a certain schema
|
6
|
+
* Now tests all available schema (a problem with specialist docs has been solved)
|
7
|
+
* Drops active-support dependency, pins json-schema dependency
|
8
|
+
|
9
|
+
# 0.1.0
|
10
|
+
|
11
|
+
* First release. Allows random content generation.
|
data/README.md
CHANGED
@@ -1,55 +1,41 @@
|
|
1
1
|
# GOV.UK Schemas
|
2
2
|
|
3
|
-
Gem to work with the [
|
3
|
+
Gem to work with the [govuk-content-schemas](https://github.com/alphagov/govuk-content-schemas).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
In your Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "govuk_schemas",
|
10
|
+
gem "govuk_schemas", "~> VERSION"
|
11
11
|
```
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
|
15
|
+
[Read the documentation!](https://alphagov.github.io/govuk_schemas_gem/frames.html)
|
16
16
|
|
17
|
+
## Running the test suite
|
17
18
|
|
18
|
-
|
19
|
+
Make sure you have `govuk-content-schemas` cloned in a sibling directory:
|
19
20
|
|
20
|
-
```ruby
|
21
|
-
irb(main):001:0> GovukSchemas::RandomExample.for_frontend("detailed_guide").payload
|
22
|
-
=> {"base_path"=>"/e42dd28e9ed96dc17626ac8b1b7b8511", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
23
21
|
```
|
24
|
-
|
25
|
-
### Using it to guarantee valid data
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
irb(main):001:0> random = GovukSchemas::RandomExample.for_frontend("detailed_guide")
|
29
|
-
irb(main):002:0> random.merge_and_validate(base_path: "/foo")
|
30
|
-
=> {"base_path"=>"/foo", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
22
|
+
bundle exec rake
|
31
23
|
```
|
32
24
|
|
33
|
-
|
25
|
+
### Documentation
|
34
26
|
|
35
|
-
|
36
|
-
irb(main):001:0> random = GovukSchemas::RandomExample.for_frontend("detailed_guide")
|
37
|
-
irb(main):002:0> random.merge_and_validate(base_path: nil)
|
38
|
-
=> ERROR
|
39
|
-
```
|
27
|
+
To run a Yard server locally to preview documentation, run:
|
40
28
|
|
41
|
-
|
29
|
+
$ bundle exec yard server --reload
|
42
30
|
|
43
|
-
|
31
|
+
To rebuild the documentation, run:
|
44
32
|
|
45
|
-
|
46
|
-
bundle exec rake
|
47
|
-
```
|
33
|
+
$ bundle exec rake yard
|
48
34
|
|
49
35
|
## Releasing the gem
|
50
36
|
|
51
|
-
This gem
|
37
|
+
This gem uses [gem_publisher](https://github.com/alphagov/gem_publisher). Updating the [version](lib/govuk_schemas/version.rb) will automatically release a new version to Rubygems.
|
52
38
|
|
53
39
|
## License
|
54
40
|
|
55
|
-
The gem is available as open source under the terms of the [MIT License](
|
41
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.md).
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
require "gem_publisher"
|
4
|
+
require "yard"
|
4
5
|
|
5
6
|
RSpec::Core::RakeTask.new(:spec)
|
6
7
|
|
@@ -11,3 +12,8 @@ task :publish_gem do |_t|
|
|
11
12
|
published_gem = GemPublisher.publish_if_updated("govuk_schemas.gemspec", :rubygems)
|
12
13
|
puts "Published #{published_gem}" if published_gem
|
13
14
|
end
|
15
|
+
|
16
|
+
|
17
|
+
YARD::Rake::YardocTask.new do |t|
|
18
|
+
t.options = ['--no-private', '--markup', 'markdown', '--output-dir', 'docs']
|
19
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: GovukSchemas
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!GovukSchemas.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (G)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">GovukSchemas</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: GovukSchemas
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/govuk_schemas.rb<span class="defines">,<br />
|
83
|
+
lib/govuk_schemas/utils.rb,<br /> lib/govuk_schemas/schema.rb,<br /> lib/govuk_schemas/random.rb,<br /> lib/govuk_schemas/version.rb,<br /> lib/govuk_schemas/random_example.rb,<br /> lib/govuk_schemas/random_item_generator.rb</span>
|
84
|
+
</dd>
|
85
|
+
|
86
|
+
</dl>
|
87
|
+
<div class="clear"></div>
|
88
|
+
|
89
|
+
<h2>Defined Under Namespace</h2>
|
90
|
+
<p class="children">
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="GovukSchemas/RandomExample.html" title="GovukSchemas::RandomExample (class)">RandomExample</a></span>, <span class='object_link'><a href="GovukSchemas/Schema.html" title="GovukSchemas::Schema (class)">Schema</a></span>
|
96
|
+
|
97
|
+
|
98
|
+
</p>
|
99
|
+
|
100
|
+
<h2>Constant Summary</h2>
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
<div id="footer">
|
114
|
+
Generated on Fri Sep 23 14:26:37 2016 by
|
115
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
116
|
+
0.8.7.6 (ruby-2.3.1).
|
117
|
+
</div>
|
118
|
+
|
119
|
+
</body>
|
120
|
+
</html>
|
@@ -0,0 +1,579 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: GovukSchemas::RandomExample
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.6
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '../';
|
20
|
+
framesUrl = "../frames.html#!GovukSchemas/RandomExample.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="../_index.html">Index (R)</a> »
|
35
|
+
<span class='title'><span class='object_link'><a href="../GovukSchemas.html" title="GovukSchemas (module)">GovukSchemas</a></span></span>
|
36
|
+
»
|
37
|
+
<span class="title">RandomExample</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="../class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="../method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="../file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Class: GovukSchemas::RandomExample
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
<dt class="r1">Inherits:</dt>
|
75
|
+
<dd class="r1">
|
76
|
+
<span class="inheritName">Object</span>
|
77
|
+
|
78
|
+
<ul class="fullTree">
|
79
|
+
<li>Object</li>
|
80
|
+
|
81
|
+
<li class="next">GovukSchemas::RandomExample</li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
85
|
+
|
86
|
+
</dd>
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
<dt class="r2 last">Defined in:</dt>
|
97
|
+
<dd class="r2 last">lib/govuk_schemas/random_example.rb</dd>
|
98
|
+
|
99
|
+
</dl>
|
100
|
+
<div class="clear"></div>
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<h2>
|
111
|
+
Class Method Summary
|
112
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
113
|
+
</h2>
|
114
|
+
|
115
|
+
<ul class="summary">
|
116
|
+
|
117
|
+
<li class="public ">
|
118
|
+
<span class="summary_signature">
|
119
|
+
|
120
|
+
<a href="#for_schema-class_method" title="for_schema (class method)">+ (GovukSchemas::RandomExample) <strong>for_schema</strong>(schema_name, schema_type:) </a>
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
</span>
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
<span class="summary_desc"><div class='inline'>
|
135
|
+
<p>Returns a new <code>GovukSchemas::RandomExample</code> object.</p>
|
136
|
+
</div></span>
|
137
|
+
|
138
|
+
</li>
|
139
|
+
|
140
|
+
|
141
|
+
</ul>
|
142
|
+
|
143
|
+
<h2>
|
144
|
+
Instance Method Summary
|
145
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
146
|
+
</h2>
|
147
|
+
|
148
|
+
<ul class="summary">
|
149
|
+
|
150
|
+
<li class="public ">
|
151
|
+
<span class="summary_signature">
|
152
|
+
|
153
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (GovukSchemas::RandomExample) <strong>initialize</strong>(schema:) </a>
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
</span>
|
158
|
+
|
159
|
+
|
160
|
+
<span class="note title constructor">constructor</span>
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
<span class="summary_desc"><div class='inline'>
|
170
|
+
<p>Returns a new <code>GovukSchemas::RandomExample</code> object.</p>
|
171
|
+
</div></span>
|
172
|
+
|
173
|
+
</li>
|
174
|
+
|
175
|
+
|
176
|
+
<li class="public ">
|
177
|
+
<span class="summary_signature">
|
178
|
+
|
179
|
+
<a href="#merge_and_validate-instance_method" title="#merge_and_validate (instance method)">- (Hash) <strong>merge_and_validate</strong>(hash) </a>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
</span>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<span class="summary_desc"><div class='inline'>
|
194
|
+
<p>Return a content item merged with a hash.</p>
|
195
|
+
</div></span>
|
196
|
+
|
197
|
+
</li>
|
198
|
+
|
199
|
+
|
200
|
+
<li class="public ">
|
201
|
+
<span class="summary_signature">
|
202
|
+
|
203
|
+
<a href="#payload-instance_method" title="#payload (instance method)">- (Hash) <strong>payload</strong> </a>
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
</span>
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
<span class="summary_desc"><div class='inline'>
|
218
|
+
<p>Return a hash with a random content item.</p>
|
219
|
+
</div></span>
|
220
|
+
|
221
|
+
</li>
|
222
|
+
|
223
|
+
|
224
|
+
</ul>
|
225
|
+
|
226
|
+
|
227
|
+
<div id="constructor_details" class="method_details_list">
|
228
|
+
<h2>Constructor Details</h2>
|
229
|
+
|
230
|
+
<div class="method_details first">
|
231
|
+
<h3 class="signature first" id="initialize-instance_method">
|
232
|
+
|
233
|
+
- (<tt><span class='object_link'><a href="" title="GovukSchemas::RandomExample (class)">GovukSchemas::RandomExample</a></span></tt>) <strong>initialize</strong>(schema:)
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
</h3><div class="docstring">
|
240
|
+
<div class="discussion">
|
241
|
+
|
242
|
+
<p>Returns a new <code>GovukSchemas::RandomExample</code> object.</p>
|
243
|
+
|
244
|
+
<p>For example:</p>
|
245
|
+
|
246
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>frontend</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
247
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
248
|
+
</code></pre>
|
249
|
+
|
250
|
+
|
251
|
+
</div>
|
252
|
+
</div>
|
253
|
+
<div class="tags">
|
254
|
+
<p class="tag_title">Parameters:</p>
|
255
|
+
<ul class="param">
|
256
|
+
|
257
|
+
<li>
|
258
|
+
|
259
|
+
<span class='name'>schema</span>
|
260
|
+
|
261
|
+
|
262
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
—
|
267
|
+
<div class='inline'>
|
268
|
+
<p>A JSON schema.</p>
|
269
|
+
</div>
|
270
|
+
|
271
|
+
</li>
|
272
|
+
|
273
|
+
</ul>
|
274
|
+
|
275
|
+
|
276
|
+
</div><table class="source_code">
|
277
|
+
<tr>
|
278
|
+
<td>
|
279
|
+
<pre class="lines">
|
280
|
+
|
281
|
+
|
282
|
+
17
|
283
|
+
18
|
284
|
+
19
|
285
|
+
20</pre>
|
286
|
+
</td>
|
287
|
+
<td>
|
288
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 17</span>
|
289
|
+
|
290
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>schema:</span><span class='rparen'>)</span>
|
291
|
+
<span class='ivar'>@schema</span> <span class='op'>=</span> <span class='id identifier rubyid_schema'>schema</span>
|
292
|
+
<span class='ivar'>@random_generator</span> <span class='op'>=</span> <span class='const'>RandomItemGenerator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>schema:</span> <span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
293
|
+
<span class='kw'>end</span></pre>
|
294
|
+
</td>
|
295
|
+
</tr>
|
296
|
+
</table>
|
297
|
+
</div>
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
|
302
|
+
<div id="class_method_details" class="method_details_list">
|
303
|
+
<h2>Class Method Details</h2>
|
304
|
+
|
305
|
+
|
306
|
+
<div class="method_details first">
|
307
|
+
<h3 class="signature first" id="for_schema-class_method">
|
308
|
+
|
309
|
+
+ (<tt><span class='object_link'><a href="" title="GovukSchemas::RandomExample (class)">GovukSchemas::RandomExample</a></span></tt>) <strong>for_schema</strong>(schema_name, schema_type:)
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
</h3><div class="docstring">
|
316
|
+
<div class="discussion">
|
317
|
+
|
318
|
+
<p>Returns a new <code>GovukSchemas::RandomExample</code> object.</p>
|
319
|
+
|
320
|
+
<p>For example:</p>
|
321
|
+
|
322
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_generator'>generator</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>frontend</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
323
|
+
<span class='id identifier rubyid_generator'>generator</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
324
|
+
<span class='comment'># => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
325
|
+
</span></code></pre>
|
326
|
+
|
327
|
+
|
328
|
+
</div>
|
329
|
+
</div>
|
330
|
+
<div class="tags">
|
331
|
+
|
332
|
+
<p class="tag_title">Returns:</p>
|
333
|
+
<ul class="return">
|
334
|
+
|
335
|
+
<li>
|
336
|
+
|
337
|
+
|
338
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="GovukSchemas::RandomExample (class)">GovukSchemas::RandomExample</a></span></tt>)</span>
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
</li>
|
343
|
+
|
344
|
+
</ul>
|
345
|
+
|
346
|
+
</div><table class="source_code">
|
347
|
+
<tr>
|
348
|
+
<td>
|
349
|
+
<pre class="lines">
|
350
|
+
|
351
|
+
|
352
|
+
31
|
353
|
+
32
|
354
|
+
33
|
355
|
+
34</pre>
|
356
|
+
</td>
|
357
|
+
<td>
|
358
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 31</span>
|
359
|
+
|
360
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_name'>schema_name</span><span class='comma'>,</span> <span class='label'>schema_type:</span><span class='rparen'>)</span>
|
361
|
+
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_name'>schema_name</span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='id identifier rubyid_schema_type'>schema_type</span><span class='rparen'>)</span>
|
362
|
+
<span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>schema:</span> <span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
363
|
+
<span class='kw'>end</span></pre>
|
364
|
+
</td>
|
365
|
+
</tr>
|
366
|
+
</table>
|
367
|
+
</div>
|
368
|
+
|
369
|
+
</div>
|
370
|
+
|
371
|
+
<div id="instance_method_details" class="method_details_list">
|
372
|
+
<h2>Instance Method Details</h2>
|
373
|
+
|
374
|
+
|
375
|
+
<div class="method_details first">
|
376
|
+
<h3 class="signature first" id="merge_and_validate-instance_method">
|
377
|
+
|
378
|
+
- (<tt>Hash</tt>) <strong>merge_and_validate</strong>(hash)
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
</h3><div class="docstring">
|
385
|
+
<div class="discussion">
|
386
|
+
|
387
|
+
<p>Return a content item merged with a hash. If the resulting content item
|
388
|
+
isn't valid against the schema an error will be raised.</p>
|
389
|
+
|
390
|
+
<p>Example:</p>
|
391
|
+
|
392
|
+
<pre class="code ruby"><code class="ruby"> <span class='id identifier rubyid_random'>random</span> <span class='op'>=</span> <span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>frontend</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
393
|
+
<span class='id identifier rubyid_random'>random</span><span class='period'>.</span><span class='id identifier rubyid_merge_and_validate'>merge_and_validate</span><span class='lparen'>(</span><span class='label'>base_path:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/foo</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
394
|
+
<span class='comment'># => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
395
|
+
</span></code></pre>
|
396
|
+
|
397
|
+
|
398
|
+
</div>
|
399
|
+
</div>
|
400
|
+
<div class="tags">
|
401
|
+
<p class="tag_title">Parameters:</p>
|
402
|
+
<ul class="param">
|
403
|
+
|
404
|
+
<li>
|
405
|
+
|
406
|
+
<span class='name'>hash</span>
|
407
|
+
|
408
|
+
|
409
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
—
|
414
|
+
<div class='inline'>
|
415
|
+
<p>The hash to merge the random content with</p>
|
416
|
+
</div>
|
417
|
+
|
418
|
+
</li>
|
419
|
+
|
420
|
+
</ul>
|
421
|
+
|
422
|
+
<p class="tag_title">Returns:</p>
|
423
|
+
<ul class="return">
|
424
|
+
|
425
|
+
<li>
|
426
|
+
|
427
|
+
|
428
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
—
|
433
|
+
<div class='inline'>
|
434
|
+
<p>A content item</p>
|
435
|
+
</div>
|
436
|
+
|
437
|
+
</li>
|
438
|
+
|
439
|
+
</ul>
|
440
|
+
<p class="tag_title">Raises:</p>
|
441
|
+
<ul class="raise">
|
442
|
+
|
443
|
+
<li>
|
444
|
+
|
445
|
+
|
446
|
+
<span class='type'>(<tt><span class='object_link'>GovukSchemas::InvalidContentGenerated</span></tt>)</span>
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
</li>
|
451
|
+
|
452
|
+
</ul>
|
453
|
+
|
454
|
+
</div><table class="source_code">
|
455
|
+
<tr>
|
456
|
+
<td>
|
457
|
+
<pre class="lines">
|
458
|
+
|
459
|
+
|
460
|
+
67
|
461
|
+
68
|
462
|
+
69
|
463
|
+
70
|
464
|
+
71
|
465
|
+
72
|
466
|
+
73
|
467
|
+
74
|
468
|
+
75
|
469
|
+
76</pre>
|
470
|
+
</td>
|
471
|
+
<td>
|
472
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 67</span>
|
473
|
+
|
474
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_merge_and_validate'>merge_and_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span>
|
475
|
+
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='id identifier rubyid_payload'>payload</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='const'>Utils</span><span class='period'>.</span><span class='id identifier rubyid_stringify_keys'>stringify_keys</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
476
|
+
<span class='id identifier rubyid_errors'>errors</span> <span class='op'>=</span> <span class='id identifier rubyid_validation_errors_for'>validation_errors_for</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='rparen'>)</span>
|
477
|
+
|
478
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
|
479
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>InvalidContentGenerated</span><span class='comma'>,</span> <span class='id identifier rubyid_error_message_custom'>error_message_custom</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='comma'>,</span> <span class='id identifier rubyid_errors'>errors</span><span class='rparen'>)</span>
|
480
|
+
<span class='kw'>end</span>
|
481
|
+
|
482
|
+
<span class='id identifier rubyid_item'>item</span>
|
483
|
+
<span class='kw'>end</span></pre>
|
484
|
+
</td>
|
485
|
+
</tr>
|
486
|
+
</table>
|
487
|
+
</div>
|
488
|
+
|
489
|
+
<div class="method_details ">
|
490
|
+
<h3 class="signature " id="payload-instance_method">
|
491
|
+
|
492
|
+
- (<tt>Hash</tt>) <strong>payload</strong>
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
</h3><div class="docstring">
|
499
|
+
<div class="discussion">
|
500
|
+
|
501
|
+
<p>Return a hash with a random content item</p>
|
502
|
+
|
503
|
+
<p>Example:</p>
|
504
|
+
|
505
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>GovukSchemas</span><span class='op'>::</span><span class='const'>RandomExample</span><span class='period'>.</span><span class='id identifier rubyid_for_schema'>for_schema</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>detailed_guide</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>schema_type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>frontend</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
506
|
+
<span class='comment'># => {"base_path"=>"/e42dd28e", "title"=>"dolor est...", "publishing_app"=>"elit"...}
|
507
|
+
</span></code></pre>
|
508
|
+
|
509
|
+
|
510
|
+
</div>
|
511
|
+
</div>
|
512
|
+
<div class="tags">
|
513
|
+
|
514
|
+
<p class="tag_title">Returns:</p>
|
515
|
+
<ul class="return">
|
516
|
+
|
517
|
+
<li>
|
518
|
+
|
519
|
+
|
520
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
—
|
525
|
+
<div class='inline'>
|
526
|
+
<p>A content item</p>
|
527
|
+
</div>
|
528
|
+
|
529
|
+
</li>
|
530
|
+
|
531
|
+
</ul>
|
532
|
+
|
533
|
+
</div><table class="source_code">
|
534
|
+
<tr>
|
535
|
+
<td>
|
536
|
+
<pre class="lines">
|
537
|
+
|
538
|
+
|
539
|
+
44
|
540
|
+
45
|
541
|
+
46
|
542
|
+
47
|
543
|
+
48
|
544
|
+
49
|
545
|
+
50
|
546
|
+
51
|
547
|
+
52
|
548
|
+
53</pre>
|
549
|
+
</td>
|
550
|
+
<td>
|
551
|
+
<pre class="code"><span class="info file"># File 'lib/govuk_schemas/random_example.rb', line 44</span>
|
552
|
+
|
553
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_payload'>payload</span>
|
554
|
+
<span class='id identifier rubyid_item'>item</span> <span class='op'>=</span> <span class='ivar'>@random_generator</span><span class='period'>.</span><span class='id identifier rubyid_payload'>payload</span>
|
555
|
+
<span class='id identifier rubyid_errors'>errors</span> <span class='op'>=</span> <span class='id identifier rubyid_validation_errors_for'>validation_errors_for</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='rparen'>)</span>
|
556
|
+
|
557
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
|
558
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>InvalidContentGenerated</span><span class='comma'>,</span> <span class='id identifier rubyid_error_message'>error_message</span><span class='lparen'>(</span><span class='id identifier rubyid_item'>item</span><span class='comma'>,</span> <span class='id identifier rubyid_errors'>errors</span><span class='rparen'>)</span>
|
559
|
+
<span class='kw'>end</span>
|
560
|
+
|
561
|
+
<span class='id identifier rubyid_item'>item</span>
|
562
|
+
<span class='kw'>end</span></pre>
|
563
|
+
</td>
|
564
|
+
</tr>
|
565
|
+
</table>
|
566
|
+
</div>
|
567
|
+
|
568
|
+
</div>
|
569
|
+
|
570
|
+
</div>
|
571
|
+
|
572
|
+
<div id="footer">
|
573
|
+
Generated on Fri Sep 23 14:26:38 2016 by
|
574
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
575
|
+
0.8.7.6 (ruby-2.3.1).
|
576
|
+
</div>
|
577
|
+
|
578
|
+
</body>
|
579
|
+
</html>
|