From 1d86fab90f71a6e9a705fd7e937832c7b7ca53f6 Mon Sep 17 00:00:00 2001 From: Antonio Tapiador del Dujo Date: Tue, 10 Sep 2024 15:51:29 +0200 Subject: [PATCH] Inject ResourceRegistry.configuration in Resource.load --- lib/public/resource.rb | 11 ++++++++--- spec/public/resource_spec.rb | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/public/resource.rb b/lib/public/resource.rb index ef12364..158a6c9 100644 --- a/lib/public/resource.rb +++ b/lib/public/resource.rb @@ -203,8 +203,13 @@ def dump } end - sig { params(spec: T::Hash[String, T.untyped]).returns(Resource) } - def self.load(spec) + sig do + params( + spec: T::Hash[String, T.untyped], + configuration: ResourceRegistry::Configuration + ).returns(Resource) + end + def self.load(spec, configuration: ResourceRegistry.configuration) repository = spec['repository'].is_a?(Symbol) ? spec['repository'].to_s : spec['repository'] new( @@ -224,7 +229,7 @@ def self.load(spec) end, capabilities: spec['capabilities'].each_with_object({}) do |config, memo| - cap = CapabilityFactory.load(config) + cap = CapabilityFactory.load(config, capabilities: configuration.capabilities) memo[cap.class.key] = cap end, schema: SchemaRegistry::Schema.load(spec['schema']), diff --git a/spec/public/resource_spec.rb b/spec/public/resource_spec.rb index ebe78ee..b449e92 100644 --- a/spec/public/resource_spec.rb +++ b/spec/public/resource_spec.rb @@ -54,8 +54,13 @@ describe '#load' do let(:spec) { resource.dump } + let(:configuration) do + ResourceRegistry::Configuration.new.tap do |conf| + conf.register_capability(:dummy_capability, DummyCapability) + end + end - subject { described_class.load(spec) } + subject { described_class.load(spec, configuration: configuration) } it { expect(subject).to be_a(described_class) }