class Toys::Middleware::Spec

A middleware specification, including the middleware class and the arguments to pass to the constructor.

Use {Toys::Middleware.spec} to create a middleware spec.

Attributes

args[R]

@return [Array] the positional arguments to be passed to a middleware

class constructor, or the empty array if there are no positional
arguments

@return [nil] if this spec wraps a middleware object

block[R]

@return [Proc] if there is a block argument to be passed to a

middleware class constructor

@return [nil] if there is no block argument, or this spec wraps a

middleware object
kwargs[R]

@return [Hash] the keyword arguments to be passed to a middleware class

constructor, or the empty hash if there are no keyword arguments

@return [nil] if this spec wraps a middleware object

name[R]

@return [String,Symbol] if this spec represents a middleware name @return [Class] if this spec represents a middleware class @return [nil] if this spec wraps a middleware object

object[R]

@return [Toys::Middleware] if this spec wraps a middleware object @return [nil] if this spec represents a class to instantiate

Public Class Methods

new(object, name, args, kwargs, block) click to toggle source

@private

# File lib/toys/middleware.rb, line 242
def initialize(object, name, args, kwargs, block)
  @object = object
  @name = name
  @args = args
  @kwargs = kwargs
  @block = block
end

Public Instance Methods

==(other) click to toggle source

@private

# File lib/toys/middleware.rb, line 251
def ==(other)
  other.is_a?(Spec) &&
    object.eql?(other.object) &&
    name.eql?(other.name) &&
    args.eql?(other.args) &&
    kwargs.eql?(other.kwargs) &&
    block.eql?(other.block)
end
Also aliased as: eql?
build(lookup) click to toggle source

Builds a middleware for this spec, given a ModuleLookup for middleware.

If this spec wraps an existing middleware object, returns that object. Otherwise, constructs a middleware object from the spec.

@param lookup [Toys::ModuleLookup] A module lookup to resolve

middleware names

@return [Toys::Middleware] The middleware

# File lib/toys/middleware.rb, line 194
def build(lookup)
  return @object unless @object.nil?
  if @name.is_a?(::String) || @name.is_a?(::Symbol)
    klass = lookup&.lookup(@name)
    raise ::NameError, "Unknown middleware name #{@name.inspect}" if klass.nil?
  else
    klass = @name
  end
  Compat.instantiate(klass, @args, @kwargs, @block)
end
eql?(other)
Alias for: ==
hash() click to toggle source

@private

# File lib/toys/middleware.rb, line 262
def hash
  [object, name, args, kwargs, block].hash
end