Skip to content

Commit

Permalink
create input featurs by using all arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-ishitani committed Jan 20, 2025
1 parent 2323806 commit 4fd672e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/rggen/core/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module DSL
:enable_all,
:delete,
:setup_plugin,
:update_plugin,
:update_plugin
].each do |method_name|
def_delegator :'RgGen.builder', method_name
end
Expand Down
13 changes: 7 additions & 6 deletions lib/rggen/core/input_base/component_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ def create_input_data(*_args, &)
end

def create_features(component, *sources)
create_active_features(component, sources.last)
create_passive_features(component)
create_active_features(component, sources)
create_passive_features(component, sources)
end

def create_active_features(component, input_data)
def create_active_features(component, sources)
active_feature_factories.each do |name, factory|
create_feature(component, factory, input_data[name])
input_data = sources.last[name]
create_feature(component, factory, *sources[0..-2], input_data)
end
end

def create_passive_features(component)
def create_passive_features(component, sources)
passive_feature_factories.each_value do |factory|
create_feature(component, factory)
create_feature(component, factory, *sources[0..-2])
end
end

Expand Down
49 changes: 40 additions & 9 deletions spec/rggen/core/input_base/component_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,41 @@ def find_child_factory(*args)

describe 'フィーチャーの生成' do
describe '能動フィーチャーの生成' do
it '生成したコンポーネントと、引数の末尾から取り出した入力値を引数として、能動フィーチャーを生成する' do
expect(foo_feature_factories[:foo_0]).to receive(:create).with(equal(component), equal(input_data[:foo_0])).and_call_original
expect(foo_feature_factories[:foo_1]).to receive(:create).with(equal(component), equal(input_data[:foo_1])).and_call_original
it '生成したコンポーネントと、引数の末尾を入力値として、能動フィーチャーを生成する' do
expect(foo_feature_factories[:foo_0])
.to receive(:create)
.with(equal(component), equal(input_data[:foo_0]))
.and_call_original
expect(foo_feature_factories[:foo_1])
.to receive(:create)
.with(equal(component), equal(input_data[:foo_1]))
.and_call_original
foo_factory.create(parent, input_data)

expect(foo_feature_factories[:foo_0])
.to receive(:create)
.with(equal(component), equal(other_input_data), equal(input_data[:foo_0]))
.and_call_original
expect(foo_feature_factories[:foo_1])
.to receive(:create)
.with(equal(component), equal(other_input_data), equal(input_data[:foo_1]))
.and_call_original
foo_factory.create(parent, other_input_data, input_data)
end
end

describe '受動フィーチャーの生成' do
it '生成したコンポーネントを引数として、受動フィーチャーを生成する' do
expect(foo_feature_factories[:foo_2]).to receive(:create).with(equal(component)).and_call_original
it '生成したコンポーネントと与えられた引数の末尾以外を引数として、受動フィーチャーを生成する' do
expect(foo_feature_factories[:foo_2])
.to receive(:create)
.with(equal(component))
.and_call_original
foo_factory.create(parent, input_data)

expect(foo_feature_factories[:foo_2])
.to receive(:create)
.with(equal(component), equal(other_input_data))
.and_call_original
foo_factory.create(parent, other_input_data, input_data)
end
end
Expand Down Expand Up @@ -199,8 +224,12 @@ def read_file(file)

foo_factory.create(other_input_data, input_files)

expect(foo_feature_factories[:foo_0]).to have_received(:create).with(anything, equal(input_datas[1][:foo_0]))
expect(bar_factory).to have_received(:create).with(anything, anything, equal(input_datas[0]))
expect(foo_feature_factories[:foo_0])
.to have_received(:create)
.with(anything, anything, equal(input_datas[1][:foo_0]))
expect(bar_factory)
.to have_received(:create)
.with(anything, anything, equal(input_datas[0]))
end
end

Expand All @@ -215,9 +244,11 @@ def read_file(file)
context '空のファイルリストを与えた場合' do
it '欠損値使って、自身の組み立てを行う' do
expect(foo_feature_factories[:foo_0])
.to receive(:create).with(anything, equal(RgGen::Core::InputBase::NAValue))
.to receive(:create)
.with(anything, anything, equal(RgGen::Core::InputBase::NAValue))
expect(foo_feature_factories[:foo_1])
.to receive(:create).with(anything, equal(RgGen::Core::InputBase::NAValue))
.to receive(:create)
.with(anything, anything, equal(RgGen::Core::InputBase::NAValue))
expect(bar_factory)
.not_to receive(:create)
foo_factory.create(other_input_data, [])
Expand Down

0 comments on commit 4fd672e

Please sign in to comment.