diff --git a/lib/rggen/core/builder/builder.rb b/lib/rggen/core/builder/builder.rb index c2214fa..9eec153 100644 --- a/lib/rggen/core/builder/builder.rb +++ b/lib/rggen/core/builder/builder.rb @@ -95,6 +95,7 @@ def register_input_components def_delegator :plugin_manager, :load_plugin def_delegator :plugin_manager, :load_plugins def_delegator :plugin_manager, :setup_plugin + def_delegator :plugin_manager, :update_plugin private diff --git a/lib/rggen/core/builder/plugin_manager.rb b/lib/rggen/core/builder/plugin_manager.rb index 7df2cc5..aaa30a6 100644 --- a/lib/rggen/core/builder/plugin_manager.rb +++ b/lib/rggen/core/builder/plugin_manager.rb @@ -77,13 +77,20 @@ def setup_plugin(plugin_name, &) @plugins << PluginSpec.new(plugin_name, &) end + def update_plugin(plugin_name) + plugin = + find_plugin(plugin_name) || + (raise PluginError.new("unknown plugin: #{plugin_name}")) + block_given? && yield(plugin) + end + def activate_plugins do_normal_activation do_addtional_activation end def activate_plugin_by_name(plugin_name) - @plugins.find { |plugin| plugin.name == plugin_name } + find_plugin(plugin_name) &.then do |plugin| plugin.activate(@builder) plugin.activate_additionally(@builder) @@ -103,6 +110,10 @@ def read_plugin_file(info) raise Core::PluginError.new("cannot load such plugin: #{info}") end + def find_plugin(plugin_name) + @plugins.find { |plugin| plugin.name == plugin_name } + end + def activate_plugin_gem(info) if (gemspec = find_gemspec(info)) gem gemspec.name, gemspec.version diff --git a/lib/rggen/core/dsl.rb b/lib/rggen/core/dsl.rb index e01c1f3..05aa8cc 100644 --- a/lib/rggen/core/dsl.rb +++ b/lib/rggen/core/dsl.rb @@ -26,7 +26,8 @@ module DSL :enable, :enable_all, :delete, - :setup_plugin + :setup_plugin, + :update_plugin, ].each do |method_name| def_delegator :'RgGen.builder', method_name end diff --git a/spec/rggen/core/builder/plugin_manager_spec.rb b/spec/rggen/core/builder/plugin_manager_spec.rb index 26d0282..74f921a 100644 --- a/spec/rggen/core/builder/plugin_manager_spec.rb +++ b/spec/rggen/core/builder/plugin_manager_spec.rb @@ -266,4 +266,22 @@ def setup_plugin_expectation(**args) end end end + + describe '#update_plugin' do + it '指定されたプラグインを更新する' do + plugin = nil + plugin_manager.setup_plugin(:foo) { plugin = _1 } + + expect { |b| plugin_manager.update_plugin(:foo, &b) } + .to yield_with_args(equal(plugin)) + end + + context '指定されたプラグインが未定義の場合' do + it 'PluginErrorを起こす' do + plugin_manager.setup_plugin(:foo) {} + expect { plugin_manager.update_plugin(:bar) } + .to raise_rggen_error RgGen::Core::PluginError, 'unknown plugin: bar' + end + end + end end diff --git a/spec/rggen/core/builder/plugin_spec_spec.rb b/spec/rggen/core/builder/plugin_spec_spec.rb index 52dbd97..f9bd113 100644 --- a/spec/rggen/core/builder/plugin_spec_spec.rb +++ b/spec/rggen/core/builder/plugin_spec_spec.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true RSpec.describe RgGen::Core::Builder::PluginSpec do - let(:plugin_spec) do - described_class.new(plugin_name, plugin_module) - end - let(:plugin_name) do :foo end