README.rdoc in event_machine-0.2.0 vs README.rdoc in event_machine-0.3.0
- old
+ new
@@ -1,42 +1,36 @@
= event_machine
- With event machine, you can keep an eye on any action on your rails controller, say in your sns website,
-when user posts a blog, you need to notice all of his friends, but it's really urgly to do like this:
+With event machine, you can keep an eye on any action on your rails controller, say in your sns website, when user posts a blog, you need to notice all of his friends, but it's really urgly to do like this:
-<pre>
+ BlogController:
+ def create
+ # new and save code
+ notice_all_friends
+ end
+ end
-BlogController:
+let's take another scenario, in your sns site, when one user makes friends with the other one, we should notice all friends of these two people, but how to?
+we'd beeter have an observer on the action, the code in the make_friends action block only concerns about building relationship between the two people, the observer then notice other people, and this is also what IoC(AOP) teach us.
-def create
- # new and save code
- notice_all_friends
-end
-
-end
-
-</pre>
-
- let's take another scenario, in your sns site, when one user makes friends with the other one, we should notice
-all friends of these two people, but how to?
- we'd beeter have an observer on the action, the code in the make_friends action block only concerns about building
-relationship between the two people, the observer then notice other people, and this is also what IoC(AOP) teach us.
-
Usage:
in your config/environment.rb:
- config.gem "event_machine", :version => ">=0.2.0"
+ gem "event_machine", :version => ">=0.2.1"
+application_controller.rb:
+
+ class ApplicationController < ActionController::Base
+ include EventMachine
+ end
+
and the generate command :
-<pre>
- ~your_project_path> script/generate event_machine create_favorite FavoriteController create
-</pre>
+ ~your_project_path> rails g event_machine create_favorite FavoriteController create
then it will generate a event file which content like following:
-<pre>
for_action FavoritesController, :create do
before do
# This will be called before FavoriteController#create
@@ -46,19 +40,17 @@
# This will be called after FavoriteController#create
end
end
-</pre>
now you can add your code in the block and after block, enjoy.
= to observe multiple actions
- to observe multiple actions, you should:
+to observe multiple actions, you should:
-<pre>
for_actions [[FavoritesController, :create], [BlogsController,:create]] do
before do
# your code goes here
end
@@ -66,11 +58,9 @@
after do
# your code goes here
end
end
-
-</pre>
== Note on Patches/Pull Requests
* Fork the project.