Class: Wurk::Middleware::Chain::Entry

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

Overview

Holds the klass + ctor args for a registered middleware. Defers instantiation until retrieve/invoke runs so each job gets a fresh object.

Whether the class declares config= is resolved once, at registration, so the common case (the setter comes from include Wurk::Middleware::ServerMiddleware) skips a respond_to? on every job × every entry. It is a fast path, not the rule: the contract is "set config if the instance is respondable" (spec §10.1), which also covers a setter defined on the singleton in initialize, one reached through method_missing, or one added to the class after it was registered — so a class that does not declare it still gets asked.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, *args) ⇒ Entry

Returns a new instance of Entry.



131
132
133
134
135
# File 'lib/wurk/middleware/chain.rb', line 131

def initialize(klass, *args)
  @klass = klass
  @args = args
  @takes_config = klass.public_method_defined?(:config=)
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



129
130
131
# File 'lib/wurk/middleware/chain.rb', line 129

def klass
  @klass
end

Instance Method Details

#make_new(config = nil) ⇒ Object



137
138
139
140
141
# File 'lib/wurk/middleware/chain.rb', line 137

def make_new(config = nil)
  instance = @klass.new(*@args)
  instance.config = config if config && (@takes_config || instance.respond_to?(:config=))
  instance
end