Class: WebPipe::App

Inherits:
Object
  • Object
show all
Includes:
Dry::Monads::Result::Mixin
Defined in:
lib/web_pipe/app.rb

Overview

Rack app built from a chain of functions that take and return a Conn.

This is the abstraction encompassing a rack application built only with the functions on Conn. RackSupport::AppWithMiddlewares takes middlewares also into account.

A rack application is something callable that takes the rack environment as an argument, and returns a rack response. So, this class needs to:

  • Take rack's environment and create a Conn struct from there.
  • Starting from the initial struct, apply the pipe of functions.
  • Convert the last Conn back to a rack response.

Conn can itself be of two different types (subclasses of it}: Conn::Ongoing and Conn::Halted. The pipe is stopped on two scenarios:

  • The end of the pipe is reached.
  • One function returns a Conn::Halted.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operations) ⇒ App

Returns a new instance of App.

Parameters:

  • operations (Array<Proc>)


35
36
37
# File 'lib/web_pipe/app.rb', line 35

def initialize(operations)
  @operations = operations
end

Instance Attribute Details

#operationsObject (readonly)

Returns the value of attribute operations.



32
33
34
# File 'lib/web_pipe/app.rb', line 32

def operations
  @operations
end

Instance Method Details

#call(env) ⇒ Object

operation doesn't return a Conn

Parameters:

  • env (Hash)

    Rack environment

Raises:

  • ConnSupport::Composition::InvalidOperationResult when an



44
45
46
47
48
49
50
51
52
# File 'lib/web_pipe/app.rb', line 44

def call(env)
  extract_rack_response(
    apply_operations(
      conn_from_env(
        env
      )
    )
  )
end