-
-
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.
Until now, once a `WebPipe` app had been initialized, there was no way to get an operation by its plug name. This changes with this commit. `WebPipe#operations` is now a hash mapping the plug name with the final operation, which can be determined whether by being resolved or injected. ```ruby require 'web_pipe' require 'web_pipe/conn_support/builder' class MyApp include WebPipe plug :hello do |conn| conn.set_response_body('Hello') end end conn = WebPipe::ConnSupport::Builder.call(Rack::MockRequest.env_for) app = MyApp.new app.operations[:hello].call(conn).response_body # => ['Hello'] ```
- Loading branch information
1 parent
054b9c3
commit 352001c
Showing
7 changed files
with
84 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ Metrics/BlockLength: | |
|
||
Naming/AccessorMethodName: | ||
Enabled: false | ||
|
||
Style/HashConversion: | ||
Enabled: false |
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 @@ | ||
# Inspecting operations | ||
|
||
Once a `WebPipe` class is initialized all its operations get resolved. It | ||
happens because they are whether [resolved](resolving_operations.md) or | ||
[injected](injecting_operations.md). The final result can be accessed through | ||
the `#operations` method: | ||
|
||
|
||
```ruby | ||
require 'web_pipe' | ||
require 'web_pipe/conn_support/builder' | ||
|
||
class MyApp | ||
include WebPipe | ||
|
||
plug(:hello) do |conn| | ||
conn.set_response_body('Hello world!') | ||
end | ||
end | ||
|
||
app = MyApp.new | ||
conn = WebPipe::ConnSupport::Builder.call(Rack::MockRequest.env_for) | ||
new_conn = app.operations[:hello].call(con) | ||
conn.response_body #=> ['Hello world!'] | ||
``` |
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/conn' | ||
|
||
RSpec.describe 'Inspecting operations' do | ||
let(:pipe_class) do | ||
Class.new do | ||
include WebPipe | ||
|
||
plug :one, ->(conn) { conn.set_response_body('One') } | ||
end | ||
end | ||
|
||
it 'can inspect resolved operations' do | ||
pipe = pipe_class.new | ||
conn = build_conn(default_env) | ||
|
||
expect( | ||
pipe.operations[:one].call(conn).response_body | ||
).to eq(['One']) | ||
end | ||
|
||
it 'can inspect injected operations' do | ||
two = ->(conn) { conn.set_response_body('Two') } | ||
pipe = pipe_class.new(plugs: { one: two }) | ||
conn = build_conn(default_env) | ||
|
||
expect( | ||
pipe.operations[:one].call(conn).response_body | ||
).to eq(['Two']) | ||
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