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
@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
@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
@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
@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
@return [Toys::Middleware] if this spec wraps a middleware object @return [nil] if this spec represents a class to instantiate
Public Class Methods
@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
@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
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
@private
# File lib/toys/middleware.rb, line 262 def hash [object, name, args, kwargs, block].hash end