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