Skip to content

Commit

Permalink
Add convenient Configuration.build{...} method for constructing inl…
Browse files Browse the repository at this point in the history
…ine.
  • Loading branch information
ioquatix committed Apr 7, 2024
1 parent 8021f1f commit 42611b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/async/service/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ module Service
#
# Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults
class Configuration
def self.build(root: Dir.pwd, &block)
configuration = self.new

loader = Loader.new(configuration, root)
loader.instance_eval(&block)

return configuration
end

def self.load(paths = ARGV)
configuration = self.new

Expand Down
14 changes: 14 additions & 0 deletions test/async/service/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
require 'async/service/configuration'

describe Async::Service::Configuration do
with '.build' do
it "can create a new configuration" do
configuration = subject.build do
service 'test' do
name 'value'
end
end

expect(configuration.environments).to have_attributes(
size: be == 1
)
end
end

with '.for' do
it "can create a new configuration" do
environment = Async::Service::Environment.new
Expand Down

0 comments on commit 42611b5

Please sign in to comment.