metadata_presenter 1.9.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95c6331901af4f170f3090b864ee079ab1eb823767d0945028f7a0d55a1171ff
4
- data.tar.gz: 5aa7f0ec508ca49be80ebec1cc4dabf1b9875a254aef8df142afacf77a84a951
3
+ metadata.gz: 10a6602fbd7108b4fe94aa7d3dd4037236d051701bc7b9b41b73d5af5598c506
4
+ data.tar.gz: e0802516349bf5827a653d756f14c70e827bb7ec7e8a6bfbe6d321bfb565387a
5
5
  SHA512:
6
- metadata.gz: 27f712d97eb70864b053af2461c4be20176adccb40b59ef8ccb0fb1743b32e390535df4814cf4a973724a8d4b4d7b970bf84c22798a09f77257b6dff8d8a4ceb
7
- data.tar.gz: 8174c567a25e82ff3d46f50b6ba3e64c6fe946cd21a2716e90419d1a535410e9fadaba0fd342e908d787c6dafbbd28fb6a79a93130a8d2a71494d01859eec4a0
6
+ metadata.gz: 75c775d98418d5b1b52a07210b51b95bc122c191b261bd0c8a8b195768747cc60ad6282d14d770ca11f45eeaa36108c7aa22bd59b24dfb30614fcd012db09a8b
7
+ data.tar.gz: 71166dba57d1a2362d60583c57da0bbf7d145fd2f6e338dedf15124d74af3f47c215e72063b3efce5163075b71c33f646c5d94e93a3525dd83c4ae3732b31530
@@ -0,0 +1,13 @@
1
+ module MetadataPresenter
2
+ class Conditional < MetadataPresenter::Metadata
3
+ def ==(other)
4
+ metadata.to_h.deep_symbolize_keys == other.metadata.to_h.deep_symbolize_keys
5
+ end
6
+
7
+ def expressions
8
+ Array(metadata.expressions).map do |expression|
9
+ MetadataPresenter::Expression.new(expression)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module MetadataPresenter
2
+ class EvaluateConditionals
3
+ include ActiveModel::Model
4
+ attr_accessor :service, :flow, :user_data
5
+
6
+ def page
7
+ evaluated_page_uuid = page_uuid || flow.default_next
8
+
9
+ service.find_page_by_uuid(evaluated_page_uuid)
10
+ end
11
+
12
+ def page_uuid
13
+ @results ||= conditionals.map do |conditional|
14
+ evaluated_expressions = conditional.expressions.map do |expression|
15
+ expression.service = service
16
+
17
+ Operator.new(
18
+ expression.operator
19
+ ).evaluate(
20
+ expression.field_label,
21
+ user_data[expression.expression_component.id]
22
+ )
23
+ end
24
+
25
+ if conditional.type == 'or' && evaluated_expressions.any?
26
+ conditional.next
27
+ elsif evaluated_expressions.all?
28
+ conditional.next
29
+ end
30
+ end
31
+
32
+ @results.flatten.compact.first
33
+ end
34
+
35
+ delegate :conditionals, to: :flow
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ module MetadataPresenter
2
+ class Expression < MetadataPresenter::Metadata
3
+ attr_accessor :service
4
+
5
+ def ==(other)
6
+ metadata == other.metadata
7
+ end
8
+
9
+ def expression_page
10
+ service.find_page_by_uuid(page)
11
+ end
12
+
13
+ def expression_component
14
+ expression_page.find_component_by_uuid(component)
15
+ end
16
+
17
+ def expression_field
18
+ expression_component.find_item_by_uuid(field)
19
+ end
20
+
21
+ def field_label
22
+ expression_field['label'] if expression_field
23
+ end
24
+ end
25
+ end
@@ -8,14 +8,14 @@ module MetadataPresenter
8
8
  metadata['next']['default']
9
9
  end
10
10
 
11
- def conditions
12
- Array(metadata['next']['conditions']).map do |condition_metadata|
13
- Condition.new(condition_metadata)
11
+ def conditionals
12
+ Array(metadata['next']['conditionals']).map do |conditional_metadata|
13
+ Conditional.new(conditional_metadata)
14
14
  end
15
15
  end
16
16
 
17
17
  def group_by_page
18
- conditions.group_by(&:next)
18
+ conditionals.group_by(&:next)
19
19
  end
20
20
  end
21
21
  end
@@ -6,8 +6,8 @@ module MetadataPresenter
6
6
  def find
7
7
  return check_answers_page if return_to_check_your_answer?
8
8
 
9
- if conditions?
10
- evaluate_conditions
9
+ if conditionals?
10
+ evaluate_conditionals
11
11
  elsif current_page_flow.present?
12
12
  service.find_page_by_uuid(current_page_flow.default_next)
13
13
  else
@@ -26,14 +26,14 @@ module MetadataPresenter
26
26
  session[:return_to_check_your_answer].present?
27
27
  end
28
28
 
29
- def conditions?
29
+ def conditionals?
30
30
  current_page_flow.present? &&
31
31
  next_flow.present? &&
32
32
  next_flow_branch_object?
33
33
  end
34
34
 
35
- def evaluate_conditions
36
- EvaluateConditions.new(
35
+ def evaluate_conditionals
36
+ EvaluateConditionals.new(
37
37
  service: service,
38
38
  flow: next_flow,
39
39
  user_data: user_data
@@ -22,7 +22,7 @@ module MetadataPresenter
22
22
  flow_object = service.flow_object(page_uuid)
23
23
 
24
24
  if flow_object.branch?
25
- page = EvaluateConditions.new(
25
+ page = EvaluateConditionals.new(
26
26
  service: service,
27
27
  flow: flow_object,
28
28
  user_data: user_data
@@ -2,6 +2,6 @@
2
2
  "_type": "flow.branch",
3
3
  "next": {
4
4
  "default": "",
5
- "conditions": []
5
+ "conditionals": []
6
6
  }
7
7
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "_type": "",
3
+ "next": "",
4
+ "expressions": []
5
+ }
@@ -24,11 +24,11 @@
24
24
  "_type": "flow.branch",
25
25
  "next": {
26
26
  "default": "0b297048-aa4d-49b6-ac74-18e069118185",
27
- "conditions": [
27
+ "conditionals": [
28
28
  {
29
- "condition_type": "if",
29
+ "_type": "if",
30
30
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
31
- "criterias": [
31
+ "expressions": [
32
32
  {
33
33
  "operator": "is",
34
34
  "page": "68fbb180-9a2a-48f6-9da6-545e28b8d35a",
@@ -56,11 +56,11 @@
56
56
  "_type": "flow.branch",
57
57
  "next": {
58
58
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e",
59
- "conditions": [
59
+ "conditionals": [
60
60
  {
61
- "condition_type": "if",
61
+ "_type": "if",
62
62
  "next": "d4342dfd-0d09-4a91-a0ea-d7fd67e706cc",
63
- "criterias": [
63
+ "expressions": [
64
64
  {
65
65
  "operator": "is",
66
66
  "page": "0b297048-aa4d-49b6-ac74-18e069118185",
@@ -70,9 +70,9 @@
70
70
  ]
71
71
  },
72
72
  {
73
- "condition_type": "if",
73
+ "_type": "if",
74
74
  "next": "91e9f7c6-2f75-4b7d-9eb5-0cf352f7be66",
75
- "criterias": [
75
+ "expressions": [
76
76
  {
77
77
  "operator": "is",
78
78
  "page": "0b297048-aa4d-49b6-ac74-18e069118185",
@@ -106,11 +106,11 @@
106
106
  "_type": "flow.branch",
107
107
  "next": {
108
108
  "default": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4",
109
- "conditions": [
109
+ "conditionals": [
110
110
  {
111
- "condition_type": "if",
111
+ "_type": "if",
112
112
  "next": "8002df6e-29ab-4cdf-b520-1d7bb931a28f",
113
- "criterias": [
113
+ "expressions": [
114
114
  {
115
115
  "operator": "is_answered",
116
116
  "page": "05c3306c-0a39-42d2-9e0f-93fd49248f4e",
@@ -138,11 +138,11 @@
138
138
  "_type": "flow.branch",
139
139
  "next": {
140
140
  "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
141
- "conditions": [
141
+ "conditionals": [
142
142
  {
143
- "condition_type": "if",
143
+ "_type": "if",
144
144
  "next": "b5efc09c-ece7-45ae-b0b3-8a7905e25040",
145
- "criterias": [
145
+ "expressions": [
146
146
  {
147
147
  "operator": "is_not",
148
148
  "page": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4",
@@ -170,11 +170,11 @@
170
170
  "_type": "flow.branch",
171
171
  "next": {
172
172
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7",
173
- "conditions": [
173
+ "conditionals": [
174
174
  {
175
- "condition_type": "if",
175
+ "_type": "if",
176
176
  "next": "bc666714-c0a2-4674-afe5-faff2e20d847",
177
- "criterias": [
177
+ "expressions": [
178
178
  {
179
179
  "operator": "is",
180
180
  "page": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
@@ -184,9 +184,9 @@
184
184
  ]
185
185
  },
186
186
  {
187
- "condition_type": "if",
187
+ "_type": "if",
188
188
  "next": "e2887f44-5e8d-4dc0-b1de-496ab6039430",
189
- "criterias": [
189
+ "expressions": [
190
190
  {
191
191
  "operator": "is_not",
192
192
  "page": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
@@ -220,11 +220,11 @@
220
220
  "_type": "flow.branch",
221
221
  "next": {
222
222
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
223
- "conditions": [
223
+ "conditionals": [
224
224
  {
225
- "condition_type": "or",
225
+ "_type": "or",
226
226
  "next": "2cc66e51-2c14-4023-86bf-ded49887cdb2",
227
- "criterias": [
227
+ "expressions": [
228
228
  {
229
229
  "operator": "is",
230
230
  "page": "dc7454f9-4186-48d7-b055-684d57bbcdc7",
@@ -240,9 +240,9 @@
240
240
  ]
241
241
  },
242
242
  {
243
- "condition_type": "and",
243
+ "_type": "and",
244
244
  "next": "f6c51f88-7be8-4cb7-bbfc-6c905727a051",
245
- "criterias": [
245
+ "expressions": [
246
246
  {
247
247
  "operator": "is",
248
248
  "page": "68fbb180-9a2a-48f6-9da6-545e28b8d35a",
@@ -282,11 +282,11 @@
282
282
  "_type": "flow.branch",
283
283
  "next": {
284
284
  "default": "941137d7-a1da-43fd-994a-98a4f9ea6d46",
285
- "conditions": [
285
+ "conditionals": [
286
286
  {
287
- "condition_type": "and",
287
+ "_type": "and",
288
288
  "next": "56e80942-d0a4-405a-85cd-bd1b100013d6",
289
- "criterias": [
289
+ "expressions": [
290
290
  {
291
291
  "operator": "is",
292
292
  "page": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
@@ -308,9 +308,9 @@
308
308
  ]
309
309
  },
310
310
  {
311
- "condition_type": "or",
311
+ "_type": "or",
312
312
  "next": "6324cca4-7770-4765-89b9-1cdc41f49c8b",
313
- "criterias": [
313
+ "expressions": [
314
314
  {
315
315
  "operator": "is",
316
316
  "page": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '1.9.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
@@ -48,12 +48,12 @@ module MetadataPresenter
48
48
  flow_object = service.flow_object(id)
49
49
 
50
50
  if flow_object.branch?
51
- full_description = flow_object.conditions.map.each_with_index do |condition, _index|
52
- condition.criterias.map { |criteria|
53
- criteria.service = service
51
+ full_description = flow_object.conditionals.map.each_with_index do |conditional, _index|
52
+ conditional.expressions.map { |expression|
53
+ expression.service = service
54
54
 
55
- "#{criteria.criteria_component.humanised_title} #{criteria.operator} #{criteria.field_label}"
56
- }.join(" #{condition.condition_type} ")
55
+ "#{expression.expression_component.humanised_title} #{expression.operator} #{expression.field_label}"
56
+ }.join(" #{conditional.type} ")
57
57
  end
58
58
  nodes[id] = @graphviz.add_nodes(full_description.flatten.join(' / '))
59
59
  else
@@ -72,9 +72,9 @@ module MetadataPresenter
72
72
  if flow_object.branch?
73
73
  @graphviz.add_edges(current_node, node_next, label: 'Conditions are not met', labelfontsize: 8) if node_next
74
74
 
75
- flow_object.group_by_page.each do |page_uuid, _conditions|
76
- conditions_node = nodes[page_uuid]
77
- @graphviz.add_edges(current_node, conditions_node, label: 'Conditions are met', labelfontsize: 8) if conditions_node
75
+ flow_object.group_by_page.each do |page_uuid, _conditionals|
76
+ conditionals_node = nodes[page_uuid]
77
+ @graphviz.add_edges(current_node, conditionals_node, label: 'Conditions are met', labelfontsize: 8) if conditionals_node
78
78
  end
79
79
  elsif node_next
80
80
  @graphviz.add_edges(current_node, node_next)
@@ -15,20 +15,20 @@
15
15
  "default": {
16
16
  "type": "string"
17
17
  },
18
- "conditions": {
19
- "$ref": "#/definitions/conditions"
18
+ "conditionals": {
19
+ "$ref": "#/definitions/conditionals"
20
20
  }
21
21
  }
22
22
  }
23
23
  },
24
24
  "additionalProperties": false,
25
25
  "definitions": {
26
- "conditions": {
26
+ "conditionals": {
27
27
  "type": "array",
28
28
  "items": {
29
29
  "type": "object",
30
30
  "properties": {
31
- "condition_type": {
31
+ "_type": {
32
32
  "type": "string",
33
33
  "enum": [
34
34
  "if",
@@ -39,13 +39,13 @@
39
39
  "next": {
40
40
  "type": "string"
41
41
  },
42
- "criterias": {
43
- "$ref": "#/definitions/criterias"
42
+ "expressions": {
43
+ "$ref": "#/definitions/expressions"
44
44
  }
45
45
  }
46
46
  }
47
47
  },
48
- "criterias": {
48
+ "expressions": {
49
49
  "type": "array",
50
50
  "items": {
51
51
  "type": "object",
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.9.0
4
+ version: 2.0.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-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -277,10 +277,10 @@ files:
277
277
  - app/helpers/metadata_presenter/default_text.rb
278
278
  - app/jobs/metadata_presenter/application_job.rb
279
279
  - app/models/metadata_presenter/component.rb
280
- - app/models/metadata_presenter/condition.rb
281
- - app/models/metadata_presenter/criteria.rb
280
+ - app/models/metadata_presenter/conditional.rb
282
281
  - app/models/metadata_presenter/date_field.rb
283
- - app/models/metadata_presenter/evaluate_conditions.rb
282
+ - app/models/metadata_presenter/evaluate_conditionals.rb
283
+ - app/models/metadata_presenter/expression.rb
284
284
  - app/models/metadata_presenter/file_uploader.rb
285
285
  - app/models/metadata_presenter/flow.rb
286
286
  - app/models/metadata_presenter/item.rb
@@ -359,8 +359,8 @@ files:
359
359
  - default_metadata/definition/checkbox.json
360
360
  - default_metadata/definition/radio.json
361
361
  - default_metadata/flow/branch.json
362
- - default_metadata/flow/condition.json
363
- - default_metadata/flow/criteria.json
362
+ - default_metadata/flow/conditional.json
363
+ - default_metadata/flow/expression.json
364
364
  - default_metadata/flow/page.json
365
365
  - default_metadata/page/checkanswers.json
366
366
  - default_metadata/page/confirmation.json
@@ -1,13 +0,0 @@
1
- module MetadataPresenter
2
- class Condition < MetadataPresenter::Metadata
3
- def ==(other)
4
- metadata.to_h.deep_symbolize_keys == other.metadata.to_h.deep_symbolize_keys
5
- end
6
-
7
- def criterias
8
- Array(metadata.criterias).map do |criteria|
9
- MetadataPresenter::Criteria.new(criteria)
10
- end
11
- end
12
- end
13
- end
@@ -1,25 +0,0 @@
1
- module MetadataPresenter
2
- class Criteria < MetadataPresenter::Metadata
3
- attr_accessor :service
4
-
5
- def ==(other)
6
- metadata == other.metadata
7
- end
8
-
9
- def criteria_page
10
- service.find_page_by_uuid(page)
11
- end
12
-
13
- def criteria_component
14
- criteria_page.find_component_by_uuid(component)
15
- end
16
-
17
- def criteria_field
18
- criteria_component.find_item_by_uuid(field)
19
- end
20
-
21
- def field_label
22
- criteria_field['label'] if criteria_field
23
- end
24
- end
25
- end
@@ -1,37 +0,0 @@
1
- module MetadataPresenter
2
- class EvaluateConditions
3
- include ActiveModel::Model
4
- attr_accessor :service, :flow, :user_data
5
-
6
- def page
7
- evaluated_page_uuid = page_uuid || flow.default_next
8
-
9
- service.find_page_by_uuid(evaluated_page_uuid)
10
- end
11
-
12
- def page_uuid
13
- @results ||= conditions.map do |condition|
14
- evaluated_criterias = condition.criterias.map do |criteria|
15
- criteria.service = service
16
-
17
- Operator.new(
18
- criteria.operator
19
- ).evaluate(
20
- criteria.field_label,
21
- user_data[criteria.criteria_component.id]
22
- )
23
- end
24
-
25
- if condition.condition_type == 'or' && evaluated_criterias.any?
26
- condition.next
27
- elsif evaluated_criterias.all?
28
- condition.next
29
- end
30
- end
31
-
32
- @results.flatten.compact.first
33
- end
34
-
35
- delegate :conditions, to: :flow
36
- end
37
- end
@@ -1,5 +0,0 @@
1
- {
2
- "condition_type": "",
3
- "next": "",
4
- "criterias": []
5
- }