notification_center 0.2 → 0.3

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -11,15 +11,13 @@
11
11
  In your Gemfile
12
12
 
13
13
  ```ruby
14
- gem 'notification_center', github: 'Houdini/notification_center'
14
+ gem 'notification_center'
15
15
  ```
16
16
 
17
17
  config/initializers/notification_center.rb
18
18
 
19
19
  ```ruby
20
- NotificationCenter.configure do
21
- enable_cache = true # only one event fired in one request scope, default is false
22
- end
20
+ NotificationCenter.enable_cache = true # only one event fired in one request scope, default is false
23
21
  ```
24
22
 
25
23
  ## Use
@@ -0,0 +1,33 @@
1
+ require 'set'
2
+
3
+ module NotificationCenter
4
+ class Cache
5
+ class << self
6
+ def flush_cache!
7
+ @cache = nil
8
+ end
9
+
10
+ def open_cache
11
+ @cache ||= Set.new
12
+ end
13
+
14
+ def include? key
15
+ open_cache.include? key
16
+ end
17
+
18
+ def << key
19
+ open_cache << key
20
+ end
21
+ end
22
+
23
+ def initialize app
24
+ @app = app
25
+ end
26
+
27
+ def call env
28
+ @app.call env
29
+ ensure
30
+ self.class.flush_cache!
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module NotificationCener
2
- VERSION = "0.2".freeze
2
+ VERSION = "0.3".freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'notification_center/core_ext/module'
2
2
  require 'notification_center/configuration'
3
- require 'set'
3
+ require 'notification_center/cache'
4
4
 
5
5
  module NotificationCenter
6
6
  extend Configuration
@@ -8,8 +8,6 @@ module NotificationCenter
8
8
  def events; @@events end
9
9
  def events= hash; @@events = hash end
10
10
 
11
- def flush_cache!; @cache = nil end
12
-
13
11
  def _initialize_event_store
14
12
  @@events = Hash.new Array.new
15
13
  end
@@ -31,10 +29,9 @@ module NotificationCenter
31
29
  end
32
30
 
33
31
  def _with_cache event
34
- @cache ||= Set.new
35
- unless @cache.include? event
32
+ unless NotificationCenter::Cache.include? event
36
33
  yield
37
- @cache << event
34
+ NotificationCenter::Cache << event
38
35
  end
39
36
  end
40
37
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe NotificationCenter do
5
5
  describe '.post_notification' do
6
- before { NotificationCenter.flush_cache! }
6
+ before { NotificationCenter::Cache.flush_cache! }
7
7
 
8
8
  it "should fire event handler" do
9
9
  EventListener = Class.new { observe :event }
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.2'
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-10 00:00:00.000000000 Z
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -66,11 +66,13 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - .gitignore
69
70
  - Gemfile
70
71
  - Gemfile.lock
71
72
  - README.md
72
73
  - Rakefile
73
74
  - lib/notification_center.rb
75
+ - lib/notification_center/cache.rb
74
76
  - lib/notification_center/configuration.rb
75
77
  - lib/notification_center/core_ext/module.rb
76
78
  - lib/notification_center/rspec_helpers.rb