From adcf05d45a02455b1ab245bbda0968d3ae4db976 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Fri, 22 May 2020 15:53:31 +0200 Subject: [PATCH] Update Event guides Documenting automatic loading of files and subscription of subscribers when their files are placed under the directory `app/subscribers` and end with `_subscriber.rb`. --- guides/source/developers/events/overview.html.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/guides/source/developers/events/overview.html.md b/guides/source/developers/events/overview.html.md index 23dd758d93c..730e5f5936d 100644 --- a/guides/source/developers/events/overview.html.md +++ b/guides/source/developers/events/overview.html.md @@ -95,10 +95,18 @@ method allows to map a method of the subscriber module to an event that happens in the system. If the `event_name` argument is not specified, the event name and the method name should match. -These subscribers modules are loaded with the rest of your application but -you need to manually subscribe to them. - -For example, you could subscribe to them programmatically with something like: +These subscriber modules are loaded with the rest of your application, you +don't need to manually subscribe them when: + +* `Spree::Config.events.autoload_subscribers` returns a truthy value (default); +* you put them in the directory (or any subdirectory of) `app/subscribers`; +* their filename ends with `_subscriber.rb`; + +On the other hand, if you need to resort to manual subscription because you did +not follow the naming convention explained above, or you prefer to have complete +control on what is loaded and when, you can override the default behaviour by +setting `Spree::Config.events.autoload_subscribers = false` in a initializer. +At that point you can subscribe your event subscribers, with something similar to: ```ruby if defined?(SmsLibrary)