Skip to content

Commit

Permalink
Inject ResourceRegistry.configuration in Resource.load
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Sep 11, 2024
1 parent 97faa36 commit 8a9492d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/public/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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']),
Expand Down
7 changes: 6 additions & 1 deletion spec/public/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit 8a9492d

Please sign in to comment.