From 1d89367e4fea14b1cf29c70d1a0d13361551f717 Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Fri, 19 Jan 2024 23:16:16 +0900 Subject: [PATCH] change loader priority (refs: rggen/rggen#185) --- lib/rggen/core/input_base/component_factory.rb | 2 +- .../core/input_base/component_factory_spec.rb | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/rggen/core/input_base/component_factory.rb b/lib/rggen/core/input_base/component_factory.rb index 1cbef91..3fec3c8 100644 --- a/lib/rggen/core/input_base/component_factory.rb +++ b/lib/rggen/core/input_base/component_factory.rb @@ -42,7 +42,7 @@ def load_file(file, input_data) end def find_loader(file) - loaders.find { |l| l.support?(file) } || + loaders.reverse_each.find { |l| l.support?(file) } || (raise Core::LoadError.new('unsupported file type', file)) end diff --git a/spec/rggen/core/input_base/component_factory_spec.rb b/spec/rggen/core/input_base/component_factory_spec.rb index d2ae9d4..1dbe663 100644 --- a/spec/rggen/core/input_base/component_factory_spec.rb +++ b/spec/rggen/core/input_base/component_factory_spec.rb @@ -132,14 +132,14 @@ def find_child_factory(*args) end describe '入力データの生成と入力ファイルの読み出し' do - let(:rb_loader) do + let(:rb_loaders) do loader_class = Class.new(RgGen::Core::InputBase::Loader) do support_types [:rb] def read_file(file) input_data.load_file(file) end end - loader_class.new([], {}) + [loader_class.new([], {}), loader_class.new([], {})] end let(:foo_load_data) do @@ -158,7 +158,7 @@ def read_file(file) before do foo_factory.root_factory - foo_factory.loaders [rb_loader] + foo_factory.loaders rb_loaders end before do @@ -185,10 +185,12 @@ def read_file(file) end it '対応するローダを使って、ファイルを読み出す' do - allow(rb_loader).to receive(:load_file).and_call_original + expect(rb_loaders[0]).not_to receive(:load_file) + allow(rb_loaders[1]).to receive(:load_file).and_call_original + foo_factory.create(other_input_data, input_files) - expect(rb_loader).to have_received(:load_file).with(input_files[0], equal(input_datas[1]), valid_value_lists) - expect(rb_loader).to have_received(:load_file).with(input_files[1], equal(input_datas[1]), valid_value_lists) + expect(rb_loaders[1]).to have_received(:load_file).with(input_files[0], equal(input_datas[1]), valid_value_lists) + expect(rb_loaders[1]).to have_received(:load_file).with(input_files[1], equal(input_datas[1]), valid_value_lists) end specify '読み出したデータは、自身、及び、配下のコンポーネントの組み立てに使われる' do