Skip to content

Commit

Permalink
add Layer#component_defined? method (#133, rggen/rggen#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-ishitani authored Dec 20, 2023
1 parent 072eee0 commit ab78192
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rggen/core/builder/layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def shared_context(&body)
current_shared_context(false)
end

def component_defined?(component_name)
@feature_registries.key?(component_name)
end

def define_feature(feature_names, &body)
Array(feature_names).each do |feature_name|
do_proxy_call(__method__, nil, feature_name, &body)
Expand Down
10 changes: 10 additions & 0 deletions spec/rggen/core/builder/layer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
layer.add_feature_registry(:buzz, buzz_feature_registry)
end

describe '#component_defined?' do
it '指定したコンポーネントが定義済みかどうかを返す' do
expect(layer.component_defined?(:fizz)).to eq true
expect(layer.component_defined?(:buzz)).to eq true
expect(layer.component_defined?(:foo)).to eq false
expect(layer.component_defined?(:bar)).to eq false

end
end

describe 'フィーチャーの定義' do
specify '#add_feature_registry呼び出し時に指定した登録名でフィーチャーを定義できる' do
expect(fizz_feature_registry).to receive(:define_feature).with(:foo_0).and_call_original
Expand Down

0 comments on commit ab78192

Please sign in to comment.