Skip to content

Commit

Permalink
change loader priority
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-ishitani committed Jan 19, 2024
1 parent 007002c commit 1d89367
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rggen/core/input_base/component_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions spec/rggen/core/input_base/component_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1d89367

Please sign in to comment.