Module: WebPipe::DSL::InstanceMethods Private

Defined in:
lib/web_pipe/dsl/instance_methods.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance methods for the pipe.

It is from here that you get the rack application you can route to. The initialization phase gives you the chance to inject any of the plugs or middlewares, while the instance you get has the #call method expected by rack.

The pipe state can be accessed through the pipe class, which has been configured through ClassContext.

Constant Summary collapse

EMPTY_INJECTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

No injections at all.

{
  plugs: Types::EMPTY_HASH,
  middlewares: Types::EMPTY_HASH
}.freeze
Injections =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Type for how plugs and middlewares should be injected.

Types::Strict::Hash.schema(
  plugs: Plug::Injections,
  middlewares: RackSupport::MiddlewareSpecification::Injections
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#injectionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

has been configured.



40
41
42
# File 'lib/web_pipe/dsl/instance_methods.rb', line 40

def injections
  @injections
end

#injections [Injections[]]([Injections[]]) ⇒ Object (readonly)

Injected plugs and middlewares that allow overriding what



40
# File 'lib/web_pipe/dsl/instance_methods.rb', line 40

attr_reader :injections

#middlewaresArray<RackSupport::Middlewares> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<RackSupport::Middlewares>)


49
50
51
# File 'lib/web_pipe/dsl/instance_methods.rb', line 49

def middlewares
  @middlewares
end

#operationsConnSupport::Composition::Operation[] (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/web_pipe/dsl/instance_methods.rb', line 46

def operations
  @operations
end

#rack_appRackSupport::AppWithMiddlewares[] (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/web_pipe/dsl/instance_methods.rb', line 43

def rack_app
  @rack_app
end

Instance Method Details

#call(env) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Expected interface for rack.

Parameters:

  • env (Hash)

    Rack env

Returns:

  • (Array)

    Rack response



71
72
73
# File 'lib/web_pipe/dsl/instance_methods.rb', line 71

def call(env)
  rack_app.call(env)
end

#initialize(injects = EMPTY_INJECTIONS) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/AbcSize



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/web_pipe/dsl/instance_methods.rb', line 52

def initialize(injects = EMPTY_INJECTIONS)
  @injections = Injections[injects]
  container = self.class.container
  @middlewares = RackSupport::MiddlewareSpecification.inject_and_resolve(
    self.class.middleware_specifications, injections[:middlewares]
  )
  @operations = Plug.inject_and_resolve(
    self.class.plugs, injections[:plugs], container, self
  )
  app = App.new(operations)
  @rack_app = RackSupport::AppWithMiddlewares.new(middlewares, app)
end

#to_procObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Proc for the composition of all operations.

This can be used to plug a WebPipe itself as an operation.

Examples:

class HtmlApp
  include WebPipe

  plug :html

  private

  def html(conn)
    conn.add_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

See Also:



106
107
108
109
110
111
# File 'lib/web_pipe/dsl/instance_methods.rb', line 106

def to_proc
  ConnSupport::Composition
    .new(operations)
    .method(:call)
    .to_proc
end