Class: WebPipe::RackSupport::MiddlewareSpecification Private

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/web_pipe/rack_support/middleware_specification.rb

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

Constant Summary collapse

Name =

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.

Types::Strict::Symbol.constructor(&:to_sym)
Spec =

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.

Types::Strict::Array
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.

Types::Strict::Hash.map(
  Name, Spec
).default(Types::EMPTY_HASH)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inject(middleware_specifications, 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.



23
24
25
26
27
# File 'lib/web_pipe/rack_support/middleware_specification.rb', line 23

def self.inject(middleware_specifications, injections)
  middleware_specifications.map do |middleware_spec|
    inject_middleware(middleware_spec, injections)
  end
end

.inject_middleware(middleware_spec, 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.



29
30
31
32
33
34
35
36
# File 'lib/web_pipe/rack_support/middleware_specification.rb', line 29

def self.inject_middleware(middleware_spec, injections)
  name = middleware_spec.name
  if injections.key?(name)
    middleware_spec.with(injections[name])
  else
    middleware_spec
  end
end

Instance Method Details

#callObject

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.



38
39
40
41
42
43
44
45
46
# File 'lib/web_pipe/rack_support/middleware_specification.rb', line 38

def call
  klass_or_pipe = spec[0]
  options = spec[1..] || Types::EMPTY_ARRAY
  if klass_or_pipe.respond_to?(:to_middlewares)
    klass_or_pipe.to_middlewares
  elsif klass_or_pipe.is_a?(Class)
    [Middleware.new(middleware: klass_or_pipe, options: options)]
  end
end

#with(new_spec) ⇒ 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.



48
49
50
# File 'lib/web_pipe/rack_support/middleware_specification.rb', line 48

def with(new_spec)
  new(spec: new_spec)
end