notification_center 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -14,11 +14,19 @@ In your Gemfile
14
14
  gem 'notification_center'
15
15
  ```
16
16
 
17
+ # Cache
18
+
19
+ To enable cache, in your:
20
+
17
21
  config/initializers/notification_center.rb
18
22
 
19
23
  ```ruby
20
24
  NotificationCenter.enable_cache = true # only one event fired in one request scope, default is false
21
25
  ```
26
+ Dont forget to flush cache wach request, for this in your config/application.rb in config section:
27
+ ```ruby
28
+ config.middleware.use NotificationCenter::Cache
29
+ ```
22
30
 
23
31
  ## Use
24
32
 
@@ -29,8 +29,9 @@ module NotificationCenter
29
29
 
30
30
  def _with_cache event
31
31
  unless NotificationCenter::Cache.include? event
32
- yield
32
+ result = yield
33
33
  NotificationCenter::Cache << event
34
+ return result
34
35
  end
35
36
  end
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module NotificationCener
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.3.2".freeze
3
3
  end
@@ -14,14 +14,9 @@ describe NotificationCenter do
14
14
  NotificationCenter.post_notification :imaginary_event
15
15
  end
16
16
 
17
- it "should return listener result" do
18
- EventListener = Class.new { observe :event }
19
- EventListener.should_receive(:event_handler).and_return(:result)
20
- NotificationCenter.post_notification(:event).should eql(:result)
21
- end
22
-
23
17
  context 'when cache disabled' do
24
18
  before { NotificationCenter.enable_cache = false }
19
+
25
20
  it "should not fire event twice" do
26
21
  EventListener = Class.new { observe :event }
27
22
  EventListener.should_receive(:event_handler).twice
@@ -29,6 +24,12 @@ describe NotificationCenter do
29
24
  NotificationCenter.post_notification :event
30
25
  NotificationCenter.post_notification :event
31
26
  end
27
+
28
+ it "should return result" do
29
+ EventListener = Class.new { observe :event }
30
+ EventListener.should_receive(:event_handler).and_return(:result)
31
+ NotificationCenter.post_notification(:event).should eql(:result)
32
+ end
32
33
  end
33
34
 
34
35
  context 'when cache enabled' do
@@ -41,6 +42,12 @@ describe NotificationCenter do
41
42
  NotificationCenter.post_notification :event
42
43
  NotificationCenter.post_notification :event
43
44
  end
45
+
46
+ it "should return result" do
47
+ EventListener = Class.new { observe :event }
48
+ EventListener.should_receive(:event_handler).and_return(:result)
49
+ NotificationCenter.post_notification(:event).should eql(:result)
50
+ end
44
51
  end
45
52
  end
46
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notification_center
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: