metadata_presenter 1.4.0 → 1.5.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/app/models/metadata_presenter/page_answers.rb +2 -0
- data/app/operators/metadata_presenter/base_operator.rb +10 -0
- data/app/operators/metadata_presenter/is_not_operator.rb +4 -0
- data/app/operators/metadata_presenter/is_operator.rb +4 -0
- data/app/operators/metadata_presenter/operator.rb +7 -4
- data/fixtures/branching.json +166 -1
- data/lib/metadata_presenter/version.rb +1 -1
- data/lib/tasks/metadata_presenter_tasks.rake +52 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaea9e08a797416b551fd731c80db49d05f02f75f4ac61ecf68c5861d55af9a3
|
4
|
+
data.tar.gz: e3938447849a5197cc3567c55caacdf0eea2e80e1e4eb05b42e175850d9b34cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9ac675b0c24ca6ea9a1a9556b13a1151d499750e8aa16d3fbfc5981ac2a93cb99acc03939a188886eaf1254930bcdc1634fd44461b4345ec029a0243bd4d73
|
7
|
+
data.tar.gz: bf12bf7eefe0f0376fe67801fa74507d0a8267c08106b8c0198023f09999a093090127d4f6b3e8360d2e570cc90a49a36f4263ed77b63dc2e56587ad605a95fd
|
@@ -27,6 +27,8 @@ module MetadataPresenter
|
|
27
27
|
date_answer(component.id)
|
28
28
|
elsif component && component.type == 'upload'
|
29
29
|
upload_answer(component.id)
|
30
|
+
elsif component && component.type == 'checkboxes'
|
31
|
+
answers[method_name.to_s].to_a
|
30
32
|
else
|
31
33
|
answers[method_name.to_s]
|
32
34
|
end
|
@@ -6,5 +6,15 @@ module MetadataPresenter
|
|
6
6
|
@actual = actual
|
7
7
|
@expected = expected
|
8
8
|
end
|
9
|
+
|
10
|
+
def evaluate?
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
# Method signature for collection components (a.k.a checkboxes)
|
15
|
+
#
|
16
|
+
def evaluate_collection?
|
17
|
+
evaluate?
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
@@ -10,10 +10,13 @@ module MetadataPresenter
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def evaluate(actual, expected)
|
13
|
-
klass
|
14
|
-
|
15
|
-
|
16
|
-
.
|
13
|
+
operator = klass.constantize.new(actual, expected)
|
14
|
+
|
15
|
+
if expected.is_a?(Array)
|
16
|
+
operator.evaluate_collection?
|
17
|
+
else
|
18
|
+
operator.evaluate?
|
19
|
+
end
|
17
20
|
rescue NameError
|
18
21
|
raise NoOperator,
|
19
22
|
"Operator '#{operator}' is not implemented. You need to create the class #{klass}"
|
data/fixtures/branching.json
CHANGED
@@ -137,7 +137,7 @@
|
|
137
137
|
"cf8b3e18-dacf-4e91-92e1-018035961003": {
|
138
138
|
"_type": "branch",
|
139
139
|
"next": {
|
140
|
-
"default": "
|
140
|
+
"default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
|
141
141
|
"conditions": [
|
142
142
|
{
|
143
143
|
"condition_type": "if",
|
@@ -154,6 +154,62 @@
|
|
154
154
|
]
|
155
155
|
}
|
156
156
|
},
|
157
|
+
"b5efc09c-ece7-45ae-b0b3-8a7905e25040": {
|
158
|
+
"_type": "page",
|
159
|
+
"next": {
|
160
|
+
"default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b"
|
161
|
+
}
|
162
|
+
},
|
163
|
+
"0c022e95-0748-4dda-8ba5-12fd1d2f596b": {
|
164
|
+
"_type": "page",
|
165
|
+
"next": {
|
166
|
+
"default": "618b7537-b42b-4551-ae7d-053afa4d9ca9"
|
167
|
+
}
|
168
|
+
},
|
169
|
+
"618b7537-b42b-4551-ae7d-053afa4d9ca9": {
|
170
|
+
"_type": "branch",
|
171
|
+
"next": {
|
172
|
+
"default": "e337070b-f636-49a3-a65c-f506675265f0",
|
173
|
+
"conditions": [
|
174
|
+
{
|
175
|
+
"condition_type": "if",
|
176
|
+
"next": "bc666714-c0a2-4674-afe5-faff2e20d847",
|
177
|
+
"criterias": [
|
178
|
+
{
|
179
|
+
"operator": "is",
|
180
|
+
"page": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
|
181
|
+
"component": "4c409737-80bb-48c7-afa7-6e9360b65004",
|
182
|
+
"field": "3251098f-c8e0-4ac5-a637-95fd2e1c4dc4"
|
183
|
+
}
|
184
|
+
]
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"condition_type": "if",
|
188
|
+
"next": "e2887f44-5e8d-4dc0-b1de-496ab6039430",
|
189
|
+
"criterias": [
|
190
|
+
{
|
191
|
+
"operator": "is_not",
|
192
|
+
"page": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
|
193
|
+
"component": "4c409737-80bb-48c7-afa7-6e9360b65004",
|
194
|
+
"field": "3251098f-c8e0-4ac5-a637-95fd2e1c4dc4"
|
195
|
+
}
|
196
|
+
]
|
197
|
+
}
|
198
|
+
]
|
199
|
+
}
|
200
|
+
},
|
201
|
+
"bc666714-c0a2-4674-afe5-faff2e20d847": {
|
202
|
+
"_type": "page",
|
203
|
+
"next": {
|
204
|
+
"default": "e337070b-f636-49a3-a65c-f506675265f0"
|
205
|
+
}
|
206
|
+
},
|
207
|
+
"e2887f44-5e8d-4dc0-b1de-496ab6039430": {
|
208
|
+
"_type": "page",
|
209
|
+
"next": {
|
210
|
+
"default": "e337070b-f636-49a3-a65c-f506675265f0"
|
211
|
+
}
|
212
|
+
},
|
157
213
|
"e337070b-f636-49a3-a65c-f506675265f0": {
|
158
214
|
"_type": "page",
|
159
215
|
"next": {
|
@@ -608,6 +664,115 @@
|
|
608
664
|
}
|
609
665
|
]
|
610
666
|
},
|
667
|
+
{
|
668
|
+
"_id": "page.burgers",
|
669
|
+
"url": "burgers",
|
670
|
+
"body": "Body section",
|
671
|
+
"lede": "",
|
672
|
+
"_type": "page.singlequestion",
|
673
|
+
"_uuid": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
|
674
|
+
"heading": "Question",
|
675
|
+
"components": [
|
676
|
+
{
|
677
|
+
"_id": "burgers_checkboxes_1",
|
678
|
+
"hint": "",
|
679
|
+
"name": "burgers_checkboxes_1",
|
680
|
+
"_type": "checkboxes",
|
681
|
+
"_uuid": "4c409737-80bb-48c7-afa7-6e9360b65004",
|
682
|
+
"items": [
|
683
|
+
{
|
684
|
+
"_id": "burgers_checkboxes_1_item_1",
|
685
|
+
"hint": "",
|
686
|
+
"name": "burgers_checkboxes_1",
|
687
|
+
"_type": "checkbox",
|
688
|
+
"_uuid": "3251098f-c8e0-4ac5-a637-95fd2e1c4dc4",
|
689
|
+
"label": "Beef, cheese, tomato",
|
690
|
+
"value": "value-1",
|
691
|
+
"errors": {},
|
692
|
+
"legend": "Question",
|
693
|
+
"collection": "components",
|
694
|
+
"validation": {
|
695
|
+
"required": true
|
696
|
+
}
|
697
|
+
},
|
698
|
+
{
|
699
|
+
"_id": "burgers_checkboxes_1_item_2",
|
700
|
+
"hint": "",
|
701
|
+
"name": "burgers_checkboxes_1",
|
702
|
+
"_type": "checkbox",
|
703
|
+
"_uuid": "a0717bbd-0b9f-47a0-bf2b-2a9d208e1168",
|
704
|
+
"label": "Chicken, cheese, tomato",
|
705
|
+
"value": "value-2",
|
706
|
+
"errors": {},
|
707
|
+
"legend": "Question",
|
708
|
+
"collection": "components",
|
709
|
+
"validation": {
|
710
|
+
"required": true
|
711
|
+
}
|
712
|
+
},
|
713
|
+
{
|
714
|
+
"_id": "burgers_checkboxes_1_item_3",
|
715
|
+
"hint": "",
|
716
|
+
"name": "burgers_checkboxes_1",
|
717
|
+
"_type": "checkbox",
|
718
|
+
"_uuid": "4c409737-80bb-48c7-afa7-6e9360b65004",
|
719
|
+
"label": "Mozzarella, cheddar, feta",
|
720
|
+
"value": "value-3",
|
721
|
+
"errors": {},
|
722
|
+
"legend": "Question",
|
723
|
+
"collection": "components",
|
724
|
+
"validation": {
|
725
|
+
"required": true
|
726
|
+
}
|
727
|
+
}
|
728
|
+
],
|
729
|
+
"errors": {},
|
730
|
+
"legend": "What would you like on your burger?",
|
731
|
+
"collection": "components",
|
732
|
+
"validation": {
|
733
|
+
"required": false
|
734
|
+
}
|
735
|
+
}
|
736
|
+
]
|
737
|
+
},
|
738
|
+
{
|
739
|
+
"_id": "page.global-warming",
|
740
|
+
"url": "global-warming",
|
741
|
+
"body": "What about the trees?",
|
742
|
+
"lede": "",
|
743
|
+
"_type": "page.content",
|
744
|
+
"_uuid": "bc666714-c0a2-4674-afe5-faff2e20d847",
|
745
|
+
"heading": "Global warming",
|
746
|
+
"components": [
|
747
|
+
{
|
748
|
+
"_id": "global-warming_content_1",
|
749
|
+
"name": "global-warming_content_1",
|
750
|
+
"_type": "content",
|
751
|
+
"_uuid": "957917c3-7473-4c30-b713-5aae77a1c22f",
|
752
|
+
"content": "They will come for you"
|
753
|
+
}
|
754
|
+
],
|
755
|
+
"section_heading": ""
|
756
|
+
},
|
757
|
+
{
|
758
|
+
"_id": "page.we-love-chickens",
|
759
|
+
"url": "we-love-chickens",
|
760
|
+
"body": "Cluck cluck",
|
761
|
+
"lede": "",
|
762
|
+
"_type": "page.content",
|
763
|
+
"_uuid": "e2887f44-5e8d-4dc0-b1de-496ab6039430",
|
764
|
+
"heading": "We love chickens",
|
765
|
+
"components": [
|
766
|
+
{
|
767
|
+
"_id": "global-warming_content_1",
|
768
|
+
"name": "global-warming_content_1",
|
769
|
+
"_type": "content",
|
770
|
+
"_uuid": "49ff5c79-2e63-45fe-bbf7-de0bd061b909",
|
771
|
+
"content": "Cruella ain't got nothing on Cluckeralla"
|
772
|
+
}
|
773
|
+
],
|
774
|
+
"section_heading": ""
|
775
|
+
},
|
611
776
|
{
|
612
777
|
"_id": "page.check-answers",
|
613
778
|
"url": "check-answers",
|
@@ -1,4 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'metadata_presenter/test_helpers'
|
2
|
+
|
3
|
+
namespace :metadata do
|
4
|
+
include MetadataPresenter::TestHelpers
|
5
|
+
|
6
|
+
desc 'Represent the flow objects in human readable form'
|
7
|
+
task flow: :environment do
|
8
|
+
service = MetadataPresenter::Service.new(metadata_fixture('branching'))
|
9
|
+
|
10
|
+
start_page = service.start_page
|
11
|
+
flow = service.flow(start_page.uuid)
|
12
|
+
first_page = service.find_page_by_uuid(flow.default_next)
|
13
|
+
|
14
|
+
humanized_flow = {}
|
15
|
+
|
16
|
+
humanized_flow[start_page.url] = {
|
17
|
+
next: first_page.url
|
18
|
+
}
|
19
|
+
|
20
|
+
service.metadata['flow'].each do |id, _metadata|
|
21
|
+
flow = service.flow(id)
|
22
|
+
|
23
|
+
if flow.branch?
|
24
|
+
page = service.find_page_by_uuid(flow.default_next)
|
25
|
+
humanized_flow[page.url] = {
|
26
|
+
conditions: flow.conditions.map do |condition|
|
27
|
+
{
|
28
|
+
condition_type: condition.condition_type,
|
29
|
+
criterias: condition.criterias.map do |criteria|
|
30
|
+
criteria.service = service
|
31
|
+
{
|
32
|
+
operator: criteria.operator,
|
33
|
+
page: criteria.criteria_page.url,
|
34
|
+
component: criteria.criteria_component.humanised_title,
|
35
|
+
field: criteria.field_label
|
36
|
+
}
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
}
|
41
|
+
else
|
42
|
+
page = service.find_page_by_uuid(id)
|
43
|
+
next_page = service.find_page_by_uuid(flow.default_next)
|
44
|
+
if next_page
|
45
|
+
humanized_flow[page.url] = { next: next_page.url }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
pp humanized_flow
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metadata_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MoJ Online
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|