diff --git a/agency.rb b/agency.rb index a297fc8..b81a6bb 100755 --- a/agency.rb +++ b/agency.rb @@ -65,7 +65,10 @@ def create_managers def create_middlewares instance_list = [] @middleware = configuration.middlewares.inject(nil) do |app, (klass, args, kwargs, config)| - klass.new(app, *args, **kwargs, &config).tap{ |inst| instance_list << inst } + klass.new(app, *args, **kwargs, &config).tap do |inst| + instance_list << inst + klass.installed(self) + end end # Some Middlewares will use background threads to process work. By # sleeping for a short time between checks, those threads can work diff --git a/middleware.rb b/middleware.rb index 5eb32f5..bbf7f87 100755 --- a/middleware.rb +++ b/middleware.rb @@ -40,6 +40,17 @@ def self.register_handler namespace, event, &handler end + # A callback to be run when a Middleware instance of this type is + # installed in an Agency. + def self.on_install &block + @installed_callback = block + end + + def self.installed agency + @installed_callback&.call(agency) + end + + attr_accessor :app, :storage