moorage-enlightened_observers 1.11 → 1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +6 -5
- data/Rakefile +1 -1
- metadata +1 -1
data/README.textile
CHANGED
@@ -10,7 +10,8 @@ h2. Usage
|
|
10
10
|
|
11
11
|
<pre>
|
12
12
|
class MyController < ActionController::Base
|
13
|
-
|
13
|
+
include EnlightenedObservers
|
14
|
+
enlighten_observer :my_observer<em>[, :my_second_observer]</em>
|
14
15
|
end
|
15
16
|
</pre>
|
16
17
|
|
@@ -20,16 +21,16 @@ In your observers, also <code>include EnlightenedObservers::Enlightenment</code>
|
|
20
21
|
class MyObserver < ActiveRecord::Observer
|
21
22
|
include EnlightenedObservers::Enlightenment
|
22
23
|
|
23
|
-
<
|
24
|
+
<em> def after_create(my)
|
24
25
|
...
|
25
|
-
end</
|
26
|
+
end</em>
|
26
27
|
end
|
27
28
|
</pre>
|
28
29
|
|
29
30
|
Of course, you still have to initialize any observer the normal way in <code>config/environment.rb</code>
|
30
31
|
|
31
32
|
<pre>
|
32
|
-
config.active_record.observers = :my_observer<
|
33
|
+
config.active_record.observers = :my_observer<em>[, :my_second_observer]</em>
|
33
34
|
</pre>
|
34
35
|
|
35
36
|
|
@@ -64,7 +65,7 @@ h2. How it Works
|
|
64
65
|
|
65
66
|
By adding <code>include EnlightenedObservers::Enlightenment</code> to your Observer, an <code>attr_accessor</code> for <code>controllers</code> is added, which you can access any time from your Observer. Depending on how your oberserver has been called, this variable might have been set, with the controller that was used to access and change the model this observer has been observing.
|
66
67
|
|
67
|
-
By calling <code>enlighten_observer :my_observer<
|
68
|
+
By calling <code>enlighten_observer :my_observer<em>[, :my_second_observer]</em></code> in your controllers, you're adding an around_filter to the controller that sets and unsets the observers' controller accessor. Each time a controller action is called, this around filter finds the currently running instance of the observer (using code copied from module <code>ActiveModel::Observing::ClassMethods</code>).
|
68
69
|
|
69
70
|
NOTE: we could have had the <code>enlighten_observer</code> call actually do the <code>include EnlightenedObservers::Enlightenment</code> in the Observer - however, since your observer can be run even if the model was changed through something OTHER than a controller action, we chose to decouple the two calls.
|
70
71
|
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'date'
|
|
7
7
|
|
8
8
|
GEM = "enlightened_observers"
|
9
9
|
HUMANIZED_GEM = "EnlightenedObservers"
|
10
|
-
GEM_VERSION = "1.
|
10
|
+
GEM_VERSION = "1.12"
|
11
11
|
AUTHOR = "ThriveSmart, LLC"
|
12
12
|
EMAIL = "developers@thrivesmart.com"
|
13
13
|
HOMEPAGE = "http://www.github.com/moorage/enlightened_observers"
|