Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject ResourceRegistry.configuration in Resource.load #4

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future I see space to have a Factory class only for this purpose, but let's keep evolving things :)

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
Loading