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

Add composition of WebPipe's #9

Merged
merged 3 commits into from
Jul 11, 2019
Merged

Add composition of WebPipe's #9

merged 3 commits into from
Jul 11, 2019

Conversation

waiting-for-dev
Copy link
Owner

Allow composition of WebPipe's

WebPipe representation as a proc is the composition of all its plug operations. Thus, it is itself an operation taking a Conn and returning a Conn. It can be leveraged to be plugged as any other
operation and compose WebPipe's:

class HtmlApp
  include WebPipe

  plug :html

  private

  def html(conn)
    conn.set_response_header('Content-Type', 'text/html')
  end
end

class App
  include WebPipe

  plug :html, &HtmlApp.new
  plug :body

  private

  def body(conn)
     conn.set_response_body('Hello, world!')
  end
end

This PR introduces a breaking change. with: is no longer used to specify the operation when plugging. Now it is just the second positional argument:

plug :name, 'operation'

It changes something like:

```ruby
plug :hello, with: ->(conn) { conn.put(:hello, 'hello') }
```

to

```ruby
plug :hello, ->(conn) { conn.put(:hello, 'hello') }
```
WebPipe representation as a proc is the composition of all its plug
operations. Thus, it is itself an operation taking a `Conn` and
returning a `Conn`. It can be leveraged to be plugged as any other
operation and compose WebPipe's:

```ruby
class HtmlApp
  include WebPipe

  plug :html

  private

  def html(conn)
    conn.set_response_header('Content-Type', 'text/html')
  end
end

class App
  include WebPipe

  plug :html, &HtmlApp.new
  plug :body

  private

  def body(conn)
     conn.set_response_body('Hello, world!')
  end
end
```
@waiting-for-dev waiting-for-dev added the enhancement New feature or request label Jul 11, 2019
@waiting-for-dev waiting-for-dev merged commit dfd9df4 into master Jul 11, 2019
@waiting-for-dev waiting-for-dev deleted the plug_web_pipe branch July 11, 2019 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant