Skip to content
Snippets Groups Projects
Commit c3b628e0 authored by Per 29 mei 2024 gedeeld account, daarvoor marten's avatar Per 29 mei 2024 gedeeld account, daarvoor marten
Browse files

Merge branch 'mv-remove-deprecated-seeds' into 'main'

Remove deprecated feature for loading existing seeds

See merge request !21
parents a4f91130 601f2af1
Branches
Tags
1 merge request!21Remove deprecated feature for loading existing seeds
Pipeline #92770 passed
...@@ -8,7 +8,6 @@ require "quby/compiler" ...@@ -8,7 +8,6 @@ require "quby/compiler"
output_path = "output" output_path = "output"
lookup_tables_path = "lookup_tables" lookup_tables_path = "lookup_tables"
seeds_path = "seeds"
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: quby-compile FILE_OR_DIRS [options]" opts.banner = "Usage: quby-compile FILE_OR_DIRS [options]"
...@@ -19,10 +18,6 @@ OptionParser.new do |opts| ...@@ -19,10 +18,6 @@ OptionParser.new do |opts|
opts.on("--lookup-tables=INPUT") do |value| opts.on("--lookup-tables=INPUT") do |value|
lookup_tables_path = value lookup_tables_path = value
end end
opts.on("--seeds=INPUT") do |value|
puts '--seeds is a deprecated option, questionnaire definitions should use seed_patches to conserve seed tweaks'
end
end.parse! end.parse!
paths = ARGV.flat_map do |file_or_dir| paths = ARGV.flat_map do |file_or_dir|
...@@ -41,9 +36,7 @@ paths.each do |path| ...@@ -41,9 +36,7 @@ paths.each do |path|
key = File.basename(File.dirname(path)) key = File.basename(File.dirname(path))
sourcecode = File.read(path) sourcecode = File.read(path)
last_update = File.mtime(path) last_update = File.mtime(path)
seed_path = File.join(seeds_path, "#{key}.yml") compiled = Quby::Compiler.compile(key, sourcecode, path: path, lookup_tables: lookup_tables, last_update: last_update)
seeds = File.exist?(seed_path) ? YAML.load(File.read(seed_path)) : nil
compiled = Quby::Compiler.compile(key, sourcecode, path: path, seeds: seeds, lookup_tables: lookup_tables, last_update: last_update)
FileUtils.mkdir_p(File.join(output_path, key)) FileUtils.mkdir_p(File.join(output_path, key))
compiled[:outputs].each do |type, output| compiled[:outputs].each do |type, output|
......
...@@ -29,12 +29,11 @@ require 'quby/compiler/outputs' ...@@ -29,12 +29,11 @@ require 'quby/compiler/outputs'
module Quby module Quby
module Compiler module Compiler
def self.compile(key, sourcecode, path: nil, seeds:, lookup_tables:, last_update: nil, &block) def self.compile(key, sourcecode, path: nil, lookup_tables:, last_update: nil, &block)
Quby::Compiler::Instance.new(lookup_tables: lookup_tables).compile( Quby::Compiler::Instance.new(lookup_tables: lookup_tables).compile(
key: key, key: key,
sourcecode: sourcecode, sourcecode: sourcecode,
path: path, path: path,
seeds: seeds,
last_update: last_update, last_update: last_update,
&block &block
) )
......
...@@ -7,7 +7,7 @@ module Quby ...@@ -7,7 +7,7 @@ module Quby
@lookup_tables = lookup_tables @lookup_tables = lookup_tables
end end
def compile(key:, sourcecode:, seeds:, path: nil, last_update: nil, &block) def compile(key:, sourcecode:, path: nil, last_update: nil, &block)
if block # defined in block for tests if block # defined in block for tests
questionnaire = DSL.build(key, path: path, &block) questionnaire = DSL.build(key, path: path, &block)
else # sourcecode given as string else # sourcecode given as string
...@@ -41,7 +41,7 @@ module Quby ...@@ -41,7 +41,7 @@ module Quby
seeds: Output.new( seeds: Output.new(
key: :seeds, key: :seeds,
filename: "seeds.yml", filename: "seeds.yml",
content: YAML.dump(Outputs::SeedSerializer.new(questionnaire, seeds).generate), content: YAML.dump(Outputs::SeedSerializer.new(questionnaire).generate),
), ),
quby_frontend_v1: Output.new( quby_frontend_v1: Output.new(
key: :quby_frontend_v1, key: :quby_frontend_v1,
......
...@@ -7,23 +7,19 @@ module Quby ...@@ -7,23 +7,19 @@ module Quby
attr_reader :questionnaire attr_reader :questionnaire
attr_reader :seeds attr_reader :seeds
def initialize(questionnaire, seeds) def initialize(questionnaire)
@questionnaire = questionnaire @questionnaire = questionnaire
@seeds = seeds || [] @seeds = seeds || []
end end
def generate def generate
roqua_keys = seeds.present? ? seeds.map { |seed| seed["key"] } : questionnaire.roqua_keys questionnaire.roqua_keys.map do |roqua_key|
roqua_keys.map do |roqua_key|
seed = seeds.find { |seed| seed["key"] == roqua_key } || {}
new_seed = Services::QubyProxy.new( new_seed = Services::QubyProxy.new(
questionnaire, questionnaire,
quby_key: questionnaire.key, quby_key: questionnaire.key,
roqua_key: roqua_key, roqua_key: roqua_key,
skip_score_keys_consistency_check: true skip_score_keys_consistency_check: true
).generate(seed) ).generate
Services::SeedDiff.new.apply_patch(new_seed, questionnaire.seeds_patch[roqua_key]) Services::SeedDiff.new.apply_patch(new_seed, questionnaire.seeds_patch[roqua_key])
end end
......
...@@ -22,7 +22,8 @@ module Quby ...@@ -22,7 +22,8 @@ module Quby
@options = options @options = options
end end
def generate(seed) def generate
seed = {}
question_titles = generate_question_titles question_titles = generate_question_titles
d_qtypes = {} d_qtypes = {}
vars = [] vars = []
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Quby::Compiler::Outputs::SeedSerializer do describe Quby::Compiler::Outputs::SeedSerializer do
it 'generates yaml' do it 'generates yaml' do
questionnaire = dsl("test") { title "Test" } questionnaire = dsl("test") { title "Test" }
serializer = described_class.new(questionnaire, []) serializer = described_class.new(questionnaire)
expect(serializer.generate).to match([a_hash_including('name' => "Test")]) expect(serializer.generate).to match([a_hash_including('name' => "Test")])
end end
...@@ -14,7 +14,7 @@ describe Quby::Compiler::Outputs::SeedSerializer do ...@@ -14,7 +14,7 @@ describe Quby::Compiler::Outputs::SeedSerializer do
seeds_patch "testo1" => {"name" => "Override"} seeds_patch "testo1" => {"name" => "Override"}
end end
serializer = described_class.new(questionnaire, []) serializer = described_class.new(questionnaire)
expect(serializer.generate).to match([ expect(serializer.generate).to match([
a_hash_including('key' => 'testo1', 'name' => "Override"), a_hash_including('key' => 'testo1', 'name' => "Override"),
a_hash_including('key' => 'testo2', 'name' => "Test") a_hash_including('key' => 'testo2', 'name' => "Test")
...@@ -29,11 +29,11 @@ describe Quby::Compiler::Outputs::SeedSerializer do ...@@ -29,11 +29,11 @@ describe Quby::Compiler::Outputs::SeedSerializer do
question :v_1, type: :string, title: ' 12\. vraag nummer 1' question :v_1, type: :string, title: ' 12\. vraag nummer 1'
end end
end end
serializer = described_class.new(questionnaire, []) serializer = described_class.new(questionnaire)
expect(serializer.generate.first['quests']).to eq("v_1"=>" 12. vraag nummer 1") expect(serializer.generate.first['quests']).to eq("v_1"=>" 12. vraag nummer 1")
end end
def dsl(key, &block) def dsl(key, &block)
Quby::Compiler::DSL.build(key, nil, &block) Quby::Compiler::DSL.build(key, nil, &block)
end end
end end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment