Class: Toys::Middleware::Spec
- Inherits:
-
Object
- Object
- Toys::Middleware::Spec
- Defined in:
- lib/toys/middleware.rb
Overview
A middleware specification, including the middleware class and the arguments to pass to the constructor.
Use spec to create a middleware spec.
Instance Attribute Summary collapse
- #args ⇒ Array? readonly
- #block ⇒ Proc? readonly
- #kwargs ⇒ Hash? readonly
- #name ⇒ String, ... readonly
- #object ⇒ Toys::Middleware? readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Equality check.
-
#build(lookup) ⇒ Toys::Middleware
Builds a middleware for this spec, given a ModuleLookup for middleware.
-
#hash ⇒ Integer
Return the hash code.
Instance Attribute Details
#args ⇒ Array? (readonly)
229 230 231 |
# File 'lib/toys/middleware.rb', line 229 def args @args end |
#block ⇒ Proc? (readonly)
244 245 246 |
# File 'lib/toys/middleware.rb', line 244 def block @block end |
#kwargs ⇒ Hash? (readonly)
236 237 238 |
# File 'lib/toys/middleware.rb', line 236 def kwargs @kwargs end |
#name ⇒ String, ... (readonly)
221 222 223 |
# File 'lib/toys/middleware.rb', line 221 def name @name end |
#object ⇒ Toys::Middleware? (readonly)
214 215 216 |
# File 'lib/toys/middleware.rb', line 214 def object @object end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Equality check
252 253 254 255 256 257 258 259 |
# File 'lib/toys/middleware.rb', line 252 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 |
#build(lookup) ⇒ Toys::Middleware
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.
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/toys/middleware.rb', line 199 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 |
#hash ⇒ Integer
Return the hash code
267 268 269 |
# File 'lib/toys/middleware.rb', line 267 def hash [object, name, args, kwargs, block].hash end |