Class: Toys::Middleware::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/middleware.rb

Overview

A stack of middleware specs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_specsArray<Toys::Middleware:Spec> (readonly)

The default set of middleware specs.

Returns:

  • (Array<Toys::Middleware:Spec>)


294
295
296
# File 'lib/toys/middleware.rb', line 294

def default_specs
  @default_specs
end

#post_specsArray<Toys::Middleware:Spec> (readonly)

The middleware specs that follow the default set.

Returns:

  • (Array<Toys::Middleware:Spec>)


300
301
302
# File 'lib/toys/middleware.rb', line 300

def post_specs
  @post_specs
end

#pre_specsArray<Toys::Middleware:Spec> (readonly)

The middleware specs that precede the default set.

Returns:

  • (Array<Toys::Middleware:Spec>)


288
289
290
# File 'lib/toys/middleware.rb', line 288

def pre_specs
  @pre_specs
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Equality check

Parameters:

  • other (Object)

Returns:

  • (Boolean)


341
342
343
344
345
346
# File 'lib/toys/middleware.rb', line 341

def ==(other)
  other.is_a?(Stack) &&
    pre_specs.eql?(other.pre_specs) &&
    default_specs.eql?(other.default_specs) &&
    post_specs.eql?(other.post_specs)
end

#add(name, *args, **kwargs, &block) ⇒ Object #add(array) ⇒ Object #add(middleware_object) ⇒ Object

Add a middleware spec to the stack, in the default location, which is at the end of pre_specs). See Toys::Middleware.spec for a description of the arguments you can pass.



311
312
313
# File 'lib/toys/middleware.rb', line 311

def add(middleware, *args, **kwargs, &block)
  pre_specs.push(Middleware.spec(middleware, *args, **kwargs, &block))
end

#build(middleware_lookup) ⇒ Array<Toys::Middleware>

Build the middleware in this stack.

Returns:



331
332
333
# File 'lib/toys/middleware.rb', line 331

def build(middleware_lookup)
  (@pre_specs + @default_specs + @post_specs).map { |spec| spec.build(middleware_lookup) }
end

#dupToys::Middleware::Stack

Duplicate this stack.



320
321
322
323
324
# File 'lib/toys/middleware.rb', line 320

def dup
  Stack.new(pre_specs: pre_specs.dup,
            post_specs: post_specs.dup,
            default_specs: default_specs.dup)
end

#hashInteger

Return the hash code

Returns:

  • (Integer)


354
355
356
# File 'lib/toys/middleware.rb', line 354

def hash
  [@pre_specs, @default_specs, @post_specs].hash
end