quby-compiler 0.3.1 → 0.3.3

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile.lock +5 -5
  4. data/lib/quby/compiler/dsl.rb +3 -3
  5. data/lib/quby/compiler/dsl/base.rb +2 -2
  6. data/lib/quby/compiler/dsl/calls_custom_methods.rb +1 -2
  7. data/lib/quby/compiler/dsl/charting/chart_builder.rb +3 -3
  8. data/lib/quby/compiler/dsl/charting/overview_chart_builder.rb +1 -1
  9. data/lib/quby/compiler/dsl/helpers.rb +3 -3
  10. data/lib/quby/compiler/dsl/panel_builder.rb +13 -10
  11. data/lib/quby/compiler/dsl/question_builder.rb +2 -2
  12. data/lib/quby/compiler/dsl/questionnaire_builder.rb +24 -24
  13. data/lib/quby/compiler/dsl/questions/base.rb +7 -7
  14. data/lib/quby/compiler/dsl/questions/checkbox_question_builder.rb +1 -1
  15. data/lib/quby/compiler/dsl/questions/date_question_builder.rb +1 -1
  16. data/lib/quby/compiler/dsl/questions/deprecated_question_builder.rb +1 -1
  17. data/lib/quby/compiler/dsl/questions/float_question_builder.rb +1 -1
  18. data/lib/quby/compiler/dsl/questions/integer_question_builder.rb +1 -1
  19. data/lib/quby/compiler/dsl/questions/radio_question_builder.rb +1 -1
  20. data/lib/quby/compiler/dsl/questions/select_question_builder.rb +1 -1
  21. data/lib/quby/compiler/dsl/questions/string_question_builder.rb +1 -1
  22. data/lib/quby/compiler/dsl/questions/text_question_builder.rb +1 -1
  23. data/lib/quby/compiler/dsl/score_builder.rb +1 -1
  24. data/lib/quby/compiler/dsl/table_builder.rb +5 -5
  25. data/lib/quby/compiler/entities/definition.rb +3 -2
  26. data/lib/quby/compiler/entities/questionnaire.rb +2 -2
  27. data/lib/quby/compiler/instance.rb +1 -1
  28. data/lib/quby/compiler/services/definition_validator.rb +1 -1
  29. data/lib/quby/compiler/services/quby_proxy.rb +6 -6
  30. data/lib/quby/compiler/version.rb +1 -1
  31. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d882604750c6b9e14ef80ebf8251f0cd921b7f9e7db31b843b1c279676904c4
4
- data.tar.gz: db31a32e46f675814f9ea97d00b0c8b35a45d60b895834c0aeaf0eec58c4ae57
3
+ metadata.gz: cf1f976b37af794cf97fffb6ab66d420951f6d24ade6362851e0564ac504485f
4
+ data.tar.gz: bf363984e69fd45a2ccae488f2ea587d0482dd2cbf501a7b36fffc314368b6f3
5
5
  SHA512:
6
- metadata.gz: 816477fed5ba4f5e9c1c36a0766e9e832bb8c9a37ab22e8547f8980937e98b915188a51e5154cde2c88cb0af578fb16d42d0709133c6e1b1622054cb2415e5ae
7
- data.tar.gz: 97cf01e8fd73955ce8f51e399db8017705a69785f7e48c2f4dc6c40652f17d9638b17542725803442d1c6ca567d7c79bbc49e72d2df7f60cd9481e9aa0ac11c2
6
+ metadata.gz: d3b3470eea0acae3245483e780baa6fe9e9e321fc37ba6422ac5674aeaf5e7ad2a3c145aa6260359a12da34b5d818187e0d9f6de4b177886c5764631aecfd0e2
7
+ data.tar.gz: ad44885ecf958d9cabb332081dda45710c6baa8a96620b1998c7d86c56995051547f28d7b9b2f2776ab1df5335677d6dce904b56a1c56fd565583b16db7f9e7e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.3.3
2
+
3
+ Replace `options={}` with `**options` in the builders to prevent prepare for ruby 3.0
4
+
5
+ # 0.3.2
6
+
7
+ * Fix slashes-after-numbers removal when question does not have a title
8
+
1
9
  # 0.3.1
2
10
 
3
11
  * Slashes after numbers are now removed from question titles when making RoQua seeds (quests attribute).
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quby-compiler (0.3.1)
4
+ quby-compiler (0.3.3)
5
5
  actionview (>= 5.0)
6
6
  activemodel (>= 5.0)
7
7
  activesupport (>= 5.0)
@@ -41,7 +41,7 @@ GEM
41
41
  concurrent-ruby (1.1.8)
42
42
  crass (1.0.6)
43
43
  diff-lcs (1.4.4)
44
- dry-configurable (0.12.1)
44
+ dry-configurable (0.12.0)
45
45
  concurrent-ruby (~> 1.0)
46
46
  dry-core (~> 0.5, >= 0.5.0)
47
47
  dry-container (0.7.2)
@@ -57,7 +57,7 @@ GEM
57
57
  dry-core (~> 0.5, >= 0.5)
58
58
  dry-types (~> 1.5)
59
59
  ice_nine (~> 0.11)
60
- dry-types (1.5.1)
60
+ dry-types (1.5.0)
61
61
  concurrent-ruby (~> 1.0)
62
62
  dry-container (~> 0.3)
63
63
  dry-core (~> 0.5, >= 0.5)
@@ -77,7 +77,7 @@ GEM
77
77
  nokogiri (1.11.1)
78
78
  mini_portile2 (~> 2.5.0)
79
79
  racc (~> 1.4)
80
- nokogumbo (2.0.4)
80
+ nokogumbo (2.0.3)
81
81
  nokogiri (~> 1.8, >= 1.8.4)
82
82
  pry (0.13.1)
83
83
  coderay (~> 1.1)
@@ -90,7 +90,7 @@ GEM
90
90
  rails-html-sanitizer (1.3.0)
91
91
  loofah (~> 2.3)
92
92
  rake (12.3.3)
93
- redcarpet (3.5.1)
93
+ redcarpet (3.5.0)
94
94
  roqua-support (0.3.5)
95
95
  active_interaction (~> 3.0)
96
96
  activesupport (>= 5.1, < 6.1)
@@ -10,15 +10,15 @@ module Quby
10
10
  module DSL
11
11
  def self.build_from_definition(definition)
12
12
  Entities::Questionnaire.new(definition.key, last_update: definition.timestamp).tap do |questionnaire|
13
- builder = QuestionnaireBuilder.new(questionnaire)
13
+ builder = QuestionnaireBuilder.new(questionnaire, lookup_tables: definition.lookup_tables)
14
14
  builder.instance_eval(definition.sourcecode, definition.path) if definition.sourcecode
15
15
  questionnaire.callback_after_dsl_enhance_on_questions
16
16
  end
17
17
  end
18
18
 
19
- def self.build(key, sourcecode = nil, path: nil, timestamp: nil, &block)
19
+ def self.build(key, sourcecode = nil, path: nil, timestamp: nil, lookup_tables: {}, &block)
20
20
  Entities::Questionnaire.new(key, last_update: timestamp).tap do |questionnaire|
21
- builder = QuestionnaireBuilder.new(questionnaire)
21
+ builder = QuestionnaireBuilder.new(questionnaire, lookup_tables: lookup_tables)
22
22
  builder.instance_eval(sourcecode, path || key) if sourcecode
23
23
  builder.instance_eval(&block) if block
24
24
  questionnaire.callback_after_dsl_enhance_on_questions
@@ -9,8 +9,8 @@ module Quby
9
9
  class Base
10
10
  include Helpers
11
11
 
12
- def self.build(*args, &block)
13
- builder = new(*args)
12
+ def self.build(*args, **kwargs, &block)
13
+ builder = new(*args, **kwargs)
14
14
  builder.instance_eval(&block) if block
15
15
  builder.build
16
16
  end
@@ -6,8 +6,7 @@ module Quby
6
6
  module CallsCustomMethods
7
7
  attr_reader :custom_methods
8
8
 
9
- def initialize(*args)
10
- options = args.last.is_a?(::Hash) ? args.last : {}
9
+ def initialize(*args, **options)
11
10
  @custom_methods = options[:custom_methods] || {}
12
11
  super
13
12
  end
@@ -16,8 +16,8 @@ module Quby
16
16
  @chart_class
17
17
  end
18
18
 
19
- def initialize(questionnaire, key, options = {})
20
- @chart = self.class.chart_class.new(key, options)
19
+ def initialize(questionnaire, key, **options)
20
+ @chart = self.class.chart_class.new(key, **options)
21
21
  @questionnaire = questionnaire
22
22
  end
23
23
 
@@ -49,7 +49,7 @@ module Quby
49
49
  @chart.plotlines << {value: value, color: color}
50
50
  end
51
51
 
52
- def plot(key, options = {})
52
+ def plot(key, **options)
53
53
  unless plottable = @questionnaire.find_plottable(key)
54
54
  fail "Questionnaire #{@questionnaire.key} chart #{@chart.key} references unknown score or question #{key}"
55
55
  end
@@ -7,7 +7,7 @@ module Quby
7
7
  class OverviewChartBuilder < ChartBuilder
8
8
  set_chart_class(Entities::Charting::OverviewChart)
9
9
 
10
- def initialize(questionnaire, options = {})
10
+ def initialize(questionnaire, **options)
11
11
  @questionnaire = questionnaire
12
12
  @chart = self.class.chart_class.new
13
13
  end
@@ -7,8 +7,8 @@ module Quby
7
7
  include ActionView::Helpers::TagHelper
8
8
  include ActionView::Helpers::OutputSafetyHelper
9
9
 
10
- def image_tag(source, options = {})
11
- tag.img(options.reverse_merge(src: source, alt: image_alt(source)))
10
+ def image_tag(source, **options)
11
+ tag.img(**options.reverse_merge(src: source, alt: image_alt(source)))
12
12
  end
13
13
 
14
14
  # Copied from ActionController::Base.helpers.image_alt, because it will be removed from Rails 6.0, but we want
@@ -18,7 +18,7 @@ module Quby
18
18
  end
19
19
 
20
20
  def check_question_keys_uniqueness(key, options, questionnaire)
21
- keys = QuestionBuilder.build(key, options).claimed_keys
21
+ keys = QuestionBuilder.build(key, **options).claimed_keys
22
22
  if keys.any? { |k| questionnaire.key_in_use? k }
23
23
  fail "#{questionnaire.key}:#{key}: A question or option with input key #{key} is already defined."
24
24
  end
@@ -9,9 +9,9 @@ module Quby
9
9
  attr_reader :title
10
10
  attr_reader :questionnaire
11
11
 
12
- def initialize(title, options = {})
13
- @panel = Entities::Panel.new(options.merge(title: title, items: []))
14
- @default_question_options = options[:default_question_options] || {}
12
+ def initialize(title, default_question_options: {}, **options)
13
+ @panel = Entities::Panel.new({title: title, items: [], **options})
14
+ @default_question_options = default_question_options
15
15
  @questionnaire = options[:questionnaire]
16
16
  @custom_methods = options[:custom_methods] || {}
17
17
  end
@@ -41,25 +41,28 @@ module Quby
41
41
  @panel.items << Entities::Text.new('', raw_content: video_html)
42
42
  end
43
43
 
44
- def default_question_options(options = {})
44
+ def default_question_options(**options)
45
45
  @default_question_options = @default_question_options.merge(options)
46
46
  end
47
47
 
48
- def question(key, options = {}, &block)
48
+ def question(key, **options, &block)
49
49
  options = @default_question_options.merge(options).merge(questionnaire: @panel.questionnaire)
50
50
 
51
51
  check_question_keys_uniqueness key, options, @questionnaire
52
52
 
53
- question = QuestionBuilder.build(key, options, &block)
53
+ question = QuestionBuilder.build(key, **options, &block)
54
54
 
55
55
  @questionnaire.register_question(question)
56
56
  @panel.items << question
57
57
  end
58
58
 
59
- def table(options = {}, &block)
60
- table_builder = TableBuilder.new(@panel, options.merge(questionnaire: @panel.questionnaire,
61
- default_question_options: @default_question_options,
62
- custom_methods: @custom_methods))
59
+ def table(**options, &block)
60
+ table_builder = TableBuilder.new \
61
+ @panel,
62
+ questionnaire: @panel.questionnaire,
63
+ default_question_options: @default_question_options,
64
+ custom_methods: @custom_methods,
65
+ **options
63
66
  table_builder.instance_eval(&block) if block
64
67
  end
65
68
 
@@ -31,8 +31,8 @@ module Quby
31
31
  'hidden' => Questions::DeprecatedQuestionBuilder
32
32
  }
33
33
 
34
- def self.build(key, options = {}, &block)
35
- BUILDERS.fetch(options.fetch(:type).to_s).build(key, options, &block)
34
+ def self.build(key, **options, &block)
35
+ BUILDERS.fetch(options.fetch(:type).to_s).build(key, **options, &block)
36
36
  end
37
37
  end
38
38
  end
@@ -19,7 +19,7 @@ module Quby
19
19
  include StandardizedPanelGenerators
20
20
  include Helpers
21
21
 
22
- def initialize(target_instance, lookup_tables: nil)
22
+ def initialize(target_instance, lookup_tables:)
23
23
  @questionnaire = target_instance
24
24
  @lookup_tables = lookup_tables
25
25
  @default_question_options = {}
@@ -148,7 +148,7 @@ module Quby
148
148
  end
149
149
 
150
150
  def panel(title = nil, options = {}, &block)
151
- panel = PanelBuilder.build(title, options.merge(default_panel_options), &block)
151
+ panel = PanelBuilder.build(title, **options, **default_panel_options, &block)
152
152
  @questionnaire.add_panel(panel)
153
153
  end
154
154
 
@@ -167,28 +167,28 @@ module Quby
167
167
  @questionnaire.lookup_tables[key] = {levels: levels, tree: tree}
168
168
  end
169
169
 
170
- def default_question_options(options = {})
170
+ def default_question_options(**options)
171
171
  @default_question_options.merge!(options)
172
172
  end
173
173
 
174
174
  # Short-circuit the question command to perform an implicit panel
175
- def question(key, options = {}, &block)
175
+ def question(key, **options, &block)
176
176
  panel(nil, default_panel_options) do
177
- question(key, @default_question_options.merge(options).merge(questionnaire: @questionnaire), &block)
177
+ question(key, questionnaire: @questionnaire, **@default_question_options, **options, &block)
178
178
  end
179
179
  end
180
180
 
181
181
  # Short-circuit the text command to perform an implicit panel
182
- def text(value, options = {})
183
- panel(nil, default_panel_options) do
184
- text(value, options)
182
+ def text(value, **options)
183
+ panel(nil, **default_panel_options) do
184
+ text(value, **options)
185
185
  end
186
186
  end
187
187
 
188
188
  # Short-circuit the table command to perform an implicit panel
189
- def table(options = {}, &block)
190
- panel(nil, default_panel_options) do
191
- table(options, &block)
189
+ def table(**options, &block)
190
+ panel(nil, **default_panel_options) do
191
+ table(**options, &block)
192
192
  end
193
193
  end
194
194
 
@@ -197,15 +197,15 @@ module Quby
197
197
  # # variables are private to the score calculation
198
198
  # q01 + q02 + q03
199
199
  # end
200
- def variable(key, options = {}, &block)
201
- @questionnaire.add_score_calculation ScoreBuilder.new(key, options, &block).build
200
+ def variable(key, **options, &block)
201
+ @questionnaire.add_score_calculation ScoreBuilder.new(key, **options, &block).build
202
202
  end
203
203
 
204
- def score(key, options = {}, &block)
204
+ def score(key, **options, &block)
205
205
  @questionnaire.errors.add "Score #{key}", 'misses label in score call' if options[:label].blank?
206
206
  schema = options.delete(:schema)
207
207
  score_schema(key, options[:label], schema) if schema.present?
208
- variable(key, options.reverse_merge(score: true), &block)
208
+ variable(key, score: true, **options, &block)
209
209
  end
210
210
 
211
211
  def score_schema(key, label, options = nil, &block)
@@ -222,16 +222,16 @@ module Quby
222
222
  end
223
223
  end
224
224
 
225
- def attention(options = {}, &block)
226
- variable(:attention, options.reverse_merge(action: true), &block)
225
+ def attention(**options, &block)
226
+ variable(:attention, action: true, **options, &block)
227
227
  end
228
228
 
229
- def alarm(options = {}, &block)
230
- variable(:alarm, options.reverse_merge(action: true), &block)
229
+ def alarm(**options, &block)
230
+ variable(:alarm, action: true, **options, &block)
231
231
  end
232
232
 
233
- def completion(options = {}, &block)
234
- variable(:completion, options.reverse_merge(completion: true), &block)
233
+ def completion(**options, &block)
234
+ variable(:completion, completion: true, **options, &block)
235
235
  end
236
236
 
237
237
  def overview_chart(*args, &block)
@@ -255,15 +255,15 @@ module Quby
255
255
  @questionnaire.add_chart(builder.build(&block))
256
256
  end
257
257
 
258
- def flag(flag_options)
258
+ def flag(**flag_options)
259
259
  @questionnaire.add_flag flag_options
260
260
  end
261
261
 
262
- def textvar(textvar_options)
262
+ def textvar(**textvar_options)
263
263
  @questionnaire.add_textvar textvar_options
264
264
  end
265
265
 
266
- def outcome_table(table_options)
266
+ def outcome_table(**table_options)
267
267
  @questionnaire.add_outcome_table table_options
268
268
  end
269
269
 
@@ -10,8 +10,8 @@ module Quby
10
10
  attr_reader :type
11
11
  attr_reader :questionnaire
12
12
 
13
- def initialize(key, options = {})
14
- @questionnaire = options[:questionnaire]
13
+ def initialize(key, questionnaire:, **options)
14
+ @questionnaire = questionnaire
15
15
  end
16
16
 
17
17
  def build
@@ -111,7 +111,7 @@ module Quby
111
111
  end
112
112
 
113
113
  module Subquestions
114
- def initialize(key, options = {}, &block)
114
+ def initialize(key, **options, &block)
115
115
  super
116
116
  @default_question_options = options[:default_question_options] || {}
117
117
  @title_question = nil
@@ -126,7 +126,7 @@ module Quby
126
126
  super
127
127
  end
128
128
 
129
- def title_question(key, options = {}, &block)
129
+ def title_question(key, **options, &block)
130
130
  options = @default_question_options.merge({depends_on: @question.key,
131
131
  questionnaire: @questionnaire,
132
132
  parent: @question,
@@ -135,13 +135,13 @@ module Quby
135
135
 
136
136
  check_question_keys_uniqueness key, options, @questionnaire
137
137
 
138
- question = QuestionBuilder.build(key, options, &block)
138
+ question = QuestionBuilder.build(key, **options, &block)
139
139
 
140
140
  @questionnaire.register_question(question)
141
141
  @title_question = question
142
142
  end
143
143
 
144
- def question(key, options = {}, &block)
144
+ def question(key, **options, &block)
145
145
  options = @default_question_options.merge(options)
146
146
  .merge(questionnaire: @questionnaire,
147
147
  parent: @question,
@@ -149,7 +149,7 @@ module Quby
149
149
 
150
150
  check_question_keys_uniqueness key, options, @questionnaire
151
151
 
152
- question = QuestionBuilder.build(key, options, &block)
152
+ question = QuestionBuilder.build(key, **options, &block)
153
153
 
154
154
  @questionnaire.register_question(question)
155
155
  @question.options.last.questions << question
@@ -9,7 +9,7 @@ module Quby
9
9
  include Subquestions
10
10
  include InnerTitles
11
11
 
12
- def initialize(key, options = {}, &block)
12
+ def initialize(key, **options, &block)
13
13
  super
14
14
  @question = Entities::Questions::CheckboxQuestion.new(key, options)
15
15
  end
@@ -7,7 +7,7 @@ module Quby
7
7
  class DateQuestionBuilder < Base
8
8
  include MinMaxValidations
9
9
 
10
- def initialize(key, options = {}, &block)
10
+ def initialize(key, **options, &block)
11
11
  super
12
12
  @question = Entities::Questions::DateQuestion.new(key, options)
13
13
  end
@@ -7,7 +7,7 @@ module Quby
7
7
  class DeprecatedQuestionBuilder < Base
8
8
  include MultipleChoice
9
9
 
10
- def initialize(key, options = {}, &block)
10
+ def initialize(key, **options, &block)
11
11
  super
12
12
  @question = Entities::Questions::DeprecatedQuestion.new(key, options)
13
13
  end
@@ -10,7 +10,7 @@ module Quby
10
10
  include Units
11
11
  include Sizes
12
12
 
13
- def initialize(key, options = {}, &block)
13
+ def initialize(key, **options, &block)
14
14
  super
15
15
  @question = Entities::Questions::FloatQuestion.new(key, options)
16
16
  end
@@ -10,7 +10,7 @@ module Quby
10
10
  include Units
11
11
  include Sizes
12
12
 
13
- def initialize(key, options = {}, &block)
13
+ def initialize(key, **options, &block)
14
14
  super
15
15
  @question = Entities::Questions::IntegerQuestion.new(key, options)
16
16
  end
@@ -9,7 +9,7 @@ module Quby
9
9
  include Subquestions
10
10
  include InnerTitles
11
11
 
12
- def initialize(key, options = {}, &block)
12
+ def initialize(key, **options, &block)
13
13
  super
14
14
  @question = Entities::Questions::RadioQuestion.new(key, options)
15
15
  end
@@ -7,7 +7,7 @@ module Quby
7
7
  class SelectQuestionBuilder < Base
8
8
  include MultipleChoice
9
9
 
10
- def initialize(key, options = {}, &block)
10
+ def initialize(key, **options, &block)
11
11
  super
12
12
  @question = Entities::Questions::SelectQuestion.new(key, options)
13
13
  end
@@ -9,7 +9,7 @@ module Quby
9
9
  include Units
10
10
  include Sizes
11
11
 
12
- def initialize(key, options = {}, &block)
12
+ def initialize(key, **options, &block)
13
13
  super
14
14
  @question = Entities::Questions::StringQuestion.new(key, options)
15
15
  end
@@ -7,7 +7,7 @@ module Quby
7
7
  class TextQuestionBuilder < Base
8
8
  include RegexpValidations
9
9
 
10
- def initialize(key, options = {}, &block)
10
+ def initialize(key, **options, &block)
11
11
  super
12
12
  @question = Entities::Questions::TextQuestion.new(key, options)
13
13
  end
@@ -9,7 +9,7 @@ module Quby
9
9
  attr_reader :key
10
10
  attr_reader :calculation
11
11
 
12
- def initialize(key, options = {}, &block)
12
+ def initialize(key, **options, &block)
13
13
  @score = Entities::ScoreCalculation.new(key, options, &block)
14
14
  end
15
15
 
@@ -9,10 +9,10 @@ module Quby
9
9
  prepend CallsCustomMethods
10
10
  include Helpers
11
11
 
12
- def initialize(panel, options = {})
12
+ def initialize(panel, default_question_options: {}, **options)
13
13
  @panel = panel
14
14
  @table = Entities::Table.new(options)
15
- @default_question_options = options[:default_question_options] || {}
15
+ @default_question_options = default_question_options
16
16
  @panel.items << @table
17
17
  end
18
18
 
@@ -24,11 +24,11 @@ module Quby
24
24
  @table.description = value
25
25
  end
26
26
 
27
- def text(value, options = {})
27
+ def text(value, **options)
28
28
  @table.items << Entities::Text.new(value.to_s, options)
29
29
  end
30
30
 
31
- def question(key, options = {}, &block)
31
+ def question(key, **options, &block)
32
32
  options = @default_question_options.merge(options)
33
33
  .merge(table: @table,
34
34
  questionnaire: @panel.questionnaire)
@@ -36,7 +36,7 @@ module Quby
36
36
  check_question_keys_uniqueness key, options, @panel.questionnaire
37
37
  fail "You can't create a slider in a table at the moment" if options[:as] == :slider
38
38
 
39
- question = QuestionBuilder.build(key, options, &block)
39
+ question = QuestionBuilder.build(key, **options, &block)
40
40
 
41
41
  @panel.questionnaire.register_question(question)
42
42
  @table.items << question
@@ -10,13 +10,14 @@ module Quby
10
10
  extend ActiveModel::Naming
11
11
  include ActiveModel::Validations
12
12
 
13
- attr_accessor :key, :sourcecode, :timestamp, :path
13
+ attr_accessor :key, :sourcecode, :timestamp, :path, :lookup_tables
14
14
 
15
- def initialize(key:, path:, sourcecode: "", timestamp: nil)
15
+ def initialize(key:, path:, sourcecode: "", timestamp: nil, lookup_tables: {})
16
16
  @path = path
17
17
  @key = key
18
18
  @sourcecode = sourcecode
19
19
  @timestamp = timestamp
20
+ @lookup_tables = lookup_tables
20
21
  end
21
22
 
22
23
  validates_with Services::DefinitionValidator
@@ -283,7 +283,7 @@ module Quby
283
283
  end
284
284
  flag_options[:key] = flag_key
285
285
  fail(ArgumentError, "Flag '#{flag_key}' already defined") if flags.key?(flag_key)
286
- flags[flag_key] = Flag.new(flag_options)
286
+ flags[flag_key] = Flag.new(**flag_options)
287
287
  end
288
288
 
289
289
  def filter_flags(given_flags)
@@ -297,7 +297,7 @@ module Quby
297
297
  textvar_options[:key] = textvar_key
298
298
  validate_textvar_keys_unique(textvar_key)
299
299
  validate_depends_on_flag(textvar_key, textvar_options)
300
- textvars[textvar_key] = Textvar.new(textvar_options)
300
+ textvars[textvar_key] = Textvar.new(**textvar_options)
301
301
  end
302
302
 
303
303
  def filter_textvars(given_textvars)
@@ -63,7 +63,7 @@ module Quby
63
63
  end
64
64
 
65
65
  def validate(key:, sourcecode:)
66
- definition = Entities::Definition.new(key: key, sourcecode: sourcecode, path: "validating '#{key}'")
66
+ definition = Entities::Definition.new(key: key, sourcecode: sourcecode, path: "validating '#{key}'", lookup_tables: lookup_tables)
67
67
  definition.valid?
68
68
  definition
69
69
  end
@@ -30,7 +30,7 @@ module Quby
30
30
  rescue Exception => exception # rubocop:disable Lint/RescueException
31
31
  definition.errors.add(:sourcecode, {message: "Questionnaire error: #{definition.key}\n" \
32
32
  "#{exception.message}",
33
- backtrace: exception.backtrace[0..5].join("<br/>")})
33
+ backtrace: exception.backtrace[0..20]})
34
34
  end
35
35
 
36
36
  def validate_fields(questionnaire)
@@ -292,19 +292,19 @@ module Quby
292
292
 
293
293
  def strip_question_number_slashes(quests)
294
294
  quests.transform_values! do |value|
295
- value.gsub /^(\s*\d+)\\/, '\1'
295
+ value&.gsub /^(\s*\d+)\\/, '\1'
296
296
  end
297
297
  end
298
298
 
299
299
  def process_scores
300
300
  scores_from_schemas
301
301
  end
302
-
302
+
303
303
  def scores_from_schemas
304
304
  score_headers = [] # headers outcome (humanized name for subscores)
305
305
  score_keys = [] # headers data-export (not all of it, just the score_subscore part, shortened)
306
306
  score_labels = [] # score names outcome (humanized name for score as a whole)
307
-
307
+
308
308
  questionnaire.score_schemas.values.each do |score_schema|
309
309
  score_labels << score_schema.label
310
310
  score_keys << score_schema.subscore_schemas.map do |subschema|
@@ -318,18 +318,18 @@ module Quby
318
318
  hash
319
319
  end
320
320
  end
321
-
321
+
322
322
  headers = score_schema.subscore_schemas.map(&:label)
323
323
  score_headers += headers - score_headers
324
324
  end
325
-
325
+
326
326
  {
327
327
  headers: score_headers,
328
328
  keys: score_keys,
329
329
  labels: score_labels
330
330
  }
331
331
  end
332
-
332
+
333
333
  class ShortenKeysUniq
334
334
  def initialize
335
335
  @seen_results = []
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email:
141
141
  - marten@veldthuis.com
142
142
  executables:
@@ -256,7 +256,7 @@ licenses:
256
256
  - MIT
257
257
  metadata:
258
258
  homepage_uri: https://gitlab.roqua.nl/roqua/quby-compiler
259
- post_install_message:
259
+ post_install_message:
260
260
  rdoc_options: []
261
261
  require_paths:
262
262
  - lib
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  version: '0'
273
273
  requirements: []
274
274
  rubygems_version: 3.1.2
275
- signing_key:
275
+ signing_key:
276
276
  specification_version: 4
277
277
  summary: Quby::Compiler compiles a DSL for questionnaires to JSON
278
278
  test_files: []