-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a `container` setting to `WebPipe::Conn` configuration. Besides the setting, a `.container` reader attribute is added to it. This extension is meant to be a building block for other extensions. ```ruby WebPipe.load_extensions(:container) Container = {'foo' => 'bar'}.freeze WebPipe.config.container = Container WebPipe.container['foo'] # => 'bar' ```
- Loading branch information
1 parent
733632a
commit 6d2eac2
Showing
7 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module WebPipe | ||
# Adds a `container` setting to {WebPipe::Conn} configuration. | ||
# | ||
# Besides the setting, a `.container` reader attribute is added to | ||
# {WebPipe::Conn}. | ||
# | ||
# This extension is meant to be a building block for other | ||
# extensions. | ||
# | ||
# @example | ||
# WebPipe.load_extensions(:container) | ||
# | ||
# Container = {'foo' => 'bar'}.freeze | ||
# | ||
# WebPipe.config.container = Container | ||
# WebPipe.container['foo'] # => 'bar' | ||
class Conn < Dry::Struct | ||
# Container with nothing registered. | ||
EMPTY_CONTAINER = {}.freeze | ||
|
||
setting(:container, EMPTY_CONTAINER, reader: true) do |c| | ||
Types::Container[c] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
require 'support/env' | ||
require 'web_pipe/conn' | ||
|
||
RSpec.describe WebPipe::Conn do | ||
before do | ||
WebPipe.load_extensions(:container) | ||
end | ||
|
||
let(:container) { {'foo' => 'bar'}.freeze } | ||
|
||
before { WebPipe::Conn.config.container = container } | ||
|
||
describe '#config' do | ||
it "has a 'container' setting" do | ||
expect(WebPipe::Conn.config.container).to be(container) | ||
end | ||
end | ||
|
||
it "has a 'container' reader" do | ||
expect(WebPipe::Conn.container).to be(container) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters