Skip to content

Commit 42611b5

Browse files
committed
Add convenient Configuration.build{...} method for constructing inline.
1 parent 8021f1f commit 42611b5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/async/service/configuration.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ module Service
1313
#
1414
# Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults
1515
class Configuration
16+
def self.build(root: Dir.pwd, &block)
17+
configuration = self.new
18+
19+
loader = Loader.new(configuration, root)
20+
loader.instance_eval(&block)
21+
22+
return configuration
23+
end
24+
1625
def self.load(paths = ARGV)
1726
configuration = self.new
1827

test/async/service/configuration.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
require 'async/service/configuration'
77

88
describe Async::Service::Configuration do
9+
with '.build' do
10+
it "can create a new configuration" do
11+
configuration = subject.build do
12+
service 'test' do
13+
name 'value'
14+
end
15+
end
16+
17+
expect(configuration.environments).to have_attributes(
18+
size: be == 1
19+
)
20+
end
21+
end
22+
923
with '.for' do
1024
it "can create a new configuration" do
1125
environment = Async::Service::Environment.new

0 commit comments

Comments
 (0)