diff --git a/lib/rggen/core/builder/layer.rb b/lib/rggen/core/builder/layer.rb index eec0ec6..3472bd2 100644 --- a/lib/rggen/core/builder/layer.rb +++ b/lib/rggen/core/builder/layer.rb @@ -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) diff --git a/spec/rggen/core/builder/layer_spec.rb b/spec/rggen/core/builder/layer_spec.rb index cf5ce9d..a271c54 100644 --- a/spec/rggen/core/builder/layer_spec.rb +++ b/spec/rggen/core/builder/layer_spec.rb @@ -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