quby-compiler 0.5.21 → 0.5.22

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 684bb14d23f18ee9aa9be885fbfafcc36a651373daadce74ebec6951c43857b2
4
- data.tar.gz: 7337db05c0b814ab53682ff6f95c9c31224fcbb6572018c1883b961cd6bff74e
3
+ metadata.gz: 07f0d4268936ab1120ebb48d593645367e443a2b236f705de943599aa5e44847
4
+ data.tar.gz: e7462e8862d04e7b54badb52f833371aa304d42798c28c5da5edb4fe3d2be5f3
5
5
  SHA512:
6
- metadata.gz: 7928022fff7e0cb80f1e9cbb417c4d17ace6970aefd82714e67f56d460a44b5bcce00835381fd92bf98532fbc3487c6f33b56f049145e1d0f905ecb06f934d91
7
- data.tar.gz: 31322a9526b46ba8bb5cfa68eb746c1e74dcc5c29b7efd320667dbbcbe6657fdd1961a64d7fe1aa7f999e36c28ae5295a440c635d9786ec340b3c53773e92a45
6
+ metadata.gz: f34d09ad62cbcf84a1749d014c651960409c0bde03a408be228f2940f7efb81c01c97bdeb7a82889d92c16aad637bdaf8cf7674a94bf513dd78454546ee15dc5
7
+ data.tar.gz: 3743a39d0850ee252b3c9d6fa32ef8d89c6ee88e69ffd1a280f39d49af97c5635943b47fec4bce53b0ab9920d408a790e780cb09907691b779254d1957893a01
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.5.22
2
+
3
+ * quby2: Add questionKeys to panels, so we can validate completeness and make quby2 simpler.
4
+
1
5
  # 0.5.21
2
6
 
3
7
  * Allow custom methods inside info_blocks
@@ -27,13 +27,24 @@ module Quby
27
27
  visibilityRules: visibility_rules.as_json,
28
28
  sexpVariables: sexp_variables,
29
29
  cssVars: css_vars,
30
- }.compact
30
+ }.compact.tap do |json|
31
+ validate_all_questions_in_a_panel_question_keys(json)
32
+ end
33
+ end
34
+
35
+ # safeguard that question_keys_for_panel is considering all options.
36
+ def validate_all_questions_in_a_panel_question_keys(json)
37
+ missings = @questionnaire.question_hash.values.map(&:key) - json[:panels].flat_map{_1[:questionKeys]}
38
+ return if missings.empty?
39
+
40
+ raise "Not all questions are listed in a panel['questionKeys']: #{missings.join(",")}."
31
41
  end
32
42
 
33
43
  def panel(panel)
34
44
  {
35
45
  title: panel.title,
36
46
  items: panel.items.map { panel_item(_1) }.compact,
47
+ questionKeys: question_keys_for_panel(panel) # added instead of calculated in js, so we can validate completeness.
37
48
  }.compact
38
49
  end
39
50
 
@@ -51,6 +62,30 @@ module Quby
51
62
  end
52
63
  end
53
64
 
65
+ def question_keys_for_panel(panel)
66
+ panel.items.flat_map do |item|
67
+ case item
68
+ when Quby::Compiler::Entities::Question
69
+ question_keys_for_question(item)
70
+ when Quby::Compiler::Entities::InfoBlock, Quby::Compiler::Entities::Table
71
+ item.items.flat_map do |nested_item|
72
+ next unless nested_item.is_a?(Quby::Compiler::Entities::Question)
73
+ question_keys_for_question(nested_item)
74
+ end
75
+ else
76
+ []
77
+ end
78
+ end.compact
79
+ end
80
+
81
+ def question_keys_for_question(question)
82
+ keys = [question.key]
83
+ keys << question.title_question.key if question.title_question
84
+ keys + question.options&.flat_map do |option|
85
+ option.questions&.map(&:key) # We only allow subquestions one level deep.
86
+ end
87
+ end
88
+
54
89
  def info_block_item(info_block)
55
90
  {
56
91
  type: 'info',
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.5.21"
3
+ VERSION = "0.5.22"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.21
4
+ version: 0.5.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-05-23 00:00:00.000000000 Z
10
+ date: 2025-06-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activemodel