quby-compiler 0.5.20 → 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: 58538613874bd655f416eba086f07ba45321bab1306a6bd710df279e3a9cead0
4
- data.tar.gz: 1a0c1ea24a9c0fd6e8387f6b1760e14d387e1ed41061d66c8176bf642e72f64e
3
+ metadata.gz: 07f0d4268936ab1120ebb48d593645367e443a2b236f705de943599aa5e44847
4
+ data.tar.gz: e7462e8862d04e7b54badb52f833371aa304d42798c28c5da5edb4fe3d2be5f3
5
5
  SHA512:
6
- metadata.gz: 68251dfd41c4d5054e0d23c7cfa202f6acced87251d2f16b9373c5494d2cbea52955d241479d807e11af8617ced647b49769204b38907bb3728d045a254431cb
7
- data.tar.gz: 6f34cd861fec8ae281c6fffb8dea442054d5500f5e90fb5ff3594cf1d41e3dd28200e601edc29f05e68e7be32653e084f2e5c5c02ea92cbdac87c64c6581e438
6
+ metadata.gz: f34d09ad62cbcf84a1749d014c651960409c0bde03a408be228f2940f7efb81c01c97bdeb7a82889d92c16aad637bdaf8cf7674a94bf513dd78454546ee15dc5
7
+ data.tar.gz: 3743a39d0850ee252b3c9d6fa32ef8d89c6ee88e69ffd1a280f39d49af97c5635943b47fec4bce53b0ab9920d408a790e780cb09907691b779254d1957893a01
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.5.22
2
+
3
+ * quby2: Add questionKeys to panels, so we can validate completeness and make quby2 simpler.
4
+
5
+ # 0.5.21
6
+
7
+ * Allow custom methods inside info_blocks
8
+
1
9
  # 0.5.20
2
10
 
3
11
  * dsl: Add info_block support
@@ -11,9 +11,10 @@ module Quby
11
11
  delegate :panel, to: :info_block
12
12
  delegate :questionnaire, to: :panel
13
13
 
14
- def initialize(key, start_open: true, panel:, default_question_options:)
14
+ def initialize(key, start_open: true, panel:, default_question_options:, custom_methods:)
15
15
  @info_block = Entities::InfoBlock.new(key: , panel:, start_open:)
16
16
  @default_question_options = default_question_options
17
+ @custom_methods = custom_methods
17
18
  check_key_uniqueness(key, questionnaire:)
18
19
  questionnaire.fields.info_block_keys << key
19
20
  panel.items << @info_block
@@ -38,6 +39,14 @@ module Quby
38
39
  questionnaire.register_question(question)
39
40
  info_block.items << question
40
41
  end
42
+
43
+ def method_missing(method_sym, *args, **kwargs, &block)
44
+ if @custom_methods.key? method_sym
45
+ instance_exec(*args, **kwargs, &@custom_methods[method_sym])
46
+ else
47
+ super
48
+ end
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -70,6 +70,7 @@ module Quby
70
70
  key,
71
71
  panel: @panel,
72
72
  default_question_options: @default_question_options,
73
+ custom_methods: @custom_methods,
73
74
  **options
74
75
  info_block_builder.instance_eval(&block)
75
76
  end
@@ -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.20"
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.20
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-22 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