Skip to content

Commit

Permalink
Update Event guides
Browse files Browse the repository at this point in the history
Documenting automatic loading of files and subscription of subscribers
when their files are placed under the directory `app/subscribers` and
end with `_subscriber.rb`.
  • Loading branch information
spaghetticode committed May 29, 2020
1 parent 6bf34f9 commit de5ba6e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions guides/source/developers/events/overview.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de5ba6e

Please sign in to comment.