README.md in surrounded-0.9.8 vs README.md in surrounded-0.9.9
- old
+ new
@@ -473,11 +473,11 @@
This will allow you to write methods like you normally would. They are aliased internally with a prefix and the method name that you use is rewritten to add and remove the context for the objects in this context. The public API of your class remains the same, but the extra feature of wrapping your method is handled for you.
This works like Ruby's `public`,`protected`, and `private` keywords in that you can send symbols of method names to it. But `trigger` does not alter the parsing of the document like those core keywords do. In other words, you can't merely type `trigger` on one line, and have methods added afterward be treated as trigger methods.
-## Access Control for Triggers
+## Access Control / Permissions for Triggers
If you decide to build a user interface from the available triggers, you'll find you need to know what triggers are available.
Fortunately, you can make it easy.
@@ -644,9 +644,38 @@
```ruby
context = Employment.new(current_user, the_boss)
context.rebind(employee: another_user, boss: someone_else) # same context, new players
```
+
+## Background Processing
+
+While there's no specific support for background processing, your context objects make it easy for you to add your own by remembering what arguments were provided during initialization.
+
+When you initialize a context, it will keep track of the parameters and their matching arguments in a private hash called `initializer_arguments`. This allows you to write methods to create a context object and have itself sent to a background processor.
+
+```ruby
+class ExpensiveCalculation
+ extend Surrounded::Context
+
+ initialize :leader, :members
+
+ def send_to_background(trigger_method)
+ background_arguments = initializer_arguments.merge(trigger: trigger_method)
+ BackgroundProcessor.enqueue(self.class.name, **background_arguments)
+ end
+
+ class BackgroundProcessor
+ def perform(**args)
+ trigger_name = args.delete(:trigger)
+ job_class.new(args).send(trigger_name)
+ end
+ end
+end
+ExpensiveCalculation.new(some_object, some_collection).send_to_background(:do_expensive_calculation)
+```
+
+The above example is merely pseudo-code to show how `initializer_arguments` can be used. Customize it according to your own needs.
## Overview in code
Here's a view of the possibilities in code.