pubsub 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +36 -0
  3. data/README.rdoc +134 -11
  4. data/VERSION +1 -1
  5. data/lib/pubsub/pubsub.rb +1 -0
  6. metadata +58 -29
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem "ruby_events", ">=0"
4
4
 
5
5
  group :development do
6
6
  gem "shoulda", ">= 0"
7
- gem "bundler", "~> 1.0.0"
7
+ gem "bundler", ">= 1.0.0"
8
8
  gem "jeweler", "~> 1.6.4"
9
9
  gem "rcov", ">= 0"
10
10
 
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ZenTest (4.6.0)
5
+ autotest-growl (0.2.9)
6
+ diff-lcs (1.1.2)
7
+ git (1.2.5)
8
+ jeweler (1.6.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.9.2)
13
+ rcov (0.9.9)
14
+ rspec (2.6.0)
15
+ rspec-core (~> 2.6.0)
16
+ rspec-expectations (~> 2.6.0)
17
+ rspec-mocks (~> 2.6.0)
18
+ rspec-core (2.6.4)
19
+ rspec-expectations (2.6.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.6.0)
22
+ ruby_events (1.1.0)
23
+ shoulda (2.11.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ ZenTest
30
+ autotest-growl
31
+ bundler (>= 1.0.0)
32
+ jeweler (~> 1.6.4)
33
+ rcov
34
+ rspec
35
+ ruby_events
36
+ shoulda
data/README.rdoc CHANGED
@@ -1,16 +1,139 @@
1
1
  = pubsub
2
2
 
3
- Description goes here.
4
-
5
- == Contributing to pubsub
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
3
+ == DESCRIPTION:
4
+
5
+ Ruby PubSub pattern for objects. Allows to coordinate object (publisher/subscriber) communication.
6
+
7
+ == FEATURES:
8
+
9
+ * Support multithread pulisher/subscriber
10
+ * Contains message queue and dispatcher.
11
+ * Dispatcher work in main thread and sleep when message queue is empty
12
+
13
+ == USAGE:
14
+ Using pubsub is simple
15
+
16
+ require 'rubygems'
17
+ require 'ruby_events'
18
+
19
+ Include pubsub module into class
20
+
21
+ class MyPublischer
22
+ include PubSub
23
+
24
+ end
25
+
26
+ Run message queue dispatcher
27
+
28
+ PubSub.run
29
+
30
+ Message in channel with subchannels (include '/') sending throw all subchannels, e.g. for channel 'system/info' message sending to subsribers of channel 'system/info', subchannel 'system' and global channel '*'
31
+
32
+ Unsubscribe from all channels use unsubscribe method without params.
33
+
34
+ class MyPublischer
35
+ include PubSub
36
+ def initialize
37
+ subscribe "system/info", :log_info
38
+ subscribe "system/signout", :destroy
39
+ end
40
+
41
+ def destroy
42
+ unsubscribe
43
+ end
44
+ end
45
+
46
+ Unsubscribe all listeners from one channel use unsubscribe method with channel name
47
+
48
+ class TextLogger
49
+ include PubSub
50
+ def initialize
51
+ subscribe "system/info", :log_info
52
+ end
53
+
54
+ def log_info
55
+ #log to text file
56
+ end
57
+ end
58
+
59
+ class ConsoleLogger
60
+ include PubSub
61
+ def initialize
62
+ subscribe "system/info", :log_info
63
+ end
64
+
65
+ def log_info
66
+ #log to console
67
+ end
68
+ end
69
+
70
+ class LoggerManager
71
+ include PubSub
72
+
73
+ def unsubscribe_all_logger
74
+ unsubscribe "system/info"
75
+ end
76
+ end
77
+
78
+ Unsubscribe one listener from one channel use unsubscribe method with channel name and listener
79
+
80
+ class MyPublisher
81
+ include PubSub
82
+
83
+ def initialize
84
+ subscribe "system/info", :log_info
85
+ end
86
+
87
+ def destroy
88
+ unsubscribe "system/info", :log_info
89
+ end
90
+ end
91
+
92
+ == EXAMPLES:
93
+
94
+ Create object and subscribe it to channel "system/info"
95
+
96
+ class SystemLogger
97
+ include PubSub
98
+
99
+ def initialize
100
+ subscribe "system/info", :log_info
101
+ end
102
+
103
+ def destroy
104
+ unsubscribe
105
+ end
106
+
107
+ def log_info(message)
108
+ puts message
109
+
110
+ # stop pubsub dispatcher
111
+ PubSub.stop
112
+ end
113
+ end
114
+
115
+ class Publisher
116
+ include PubSub
117
+
118
+ def say_hello
119
+ publish "system/info", "Hello world!"
120
+ end
121
+ end
122
+
123
+ SystemLogger.new
124
+ publisher = Publisher.new
125
+ publisher.say_hello
126
+
127
+ # run pubsub dispatcher
128
+ PubSub.run
129
+
130
+ == INSTALL:
131
+
132
+ * gem install pubsub
133
+
134
+ == DOCS:
135
+
136
+ http://rubydoc.info/gems/pubsub
14
137
 
15
138
  == Copyright
16
139
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/pubsub/pubsub.rb CHANGED
@@ -64,6 +64,7 @@ module PubSub
64
64
 
65
65
  def PubSub.stop
66
66
  @@stopped = true
67
+ PubSub.thread.wakeup if PubSub.thread.status == "sleep"
67
68
  end
68
69
 
69
70
  protected
metadata CHANGED
@@ -1,116 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ prerelease: false
6
10
  platform: ruby
7
11
  authors:
8
12
  - Max Kazarin
9
- autorequire:
13
+ autorequire: !!null
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2011-07-17 00:00:00.000000000 +04:00
13
- default_executable:
16
+ date: 2011-07-25 00:00:00.000000000 +04:00
17
+ default_executable: !!null
14
18
  dependencies:
15
19
  - !ruby/object:Gem::Dependency
16
20
  name: ruby_events
17
- requirement: &18948040 !ruby/object:Gem::Requirement
21
+ requirement: &24511080 !ruby/object:Gem::Requirement
18
22
  none: false
19
23
  requirements:
20
24
  - - ! '>='
21
25
  - !ruby/object:Gem::Version
22
26
  version: '0'
27
+ segments:
28
+ - 0
23
29
  type: :runtime
24
30
  prerelease: false
25
- version_requirements: *18948040
31
+ version_requirements: *24511080
26
32
  - !ruby/object:Gem::Dependency
27
33
  name: shoulda
28
- requirement: &18946840 !ruby/object:Gem::Requirement
34
+ requirement: &24510180 !ruby/object:Gem::Requirement
29
35
  none: false
30
36
  requirements:
31
37
  - - ! '>='
32
38
  - !ruby/object:Gem::Version
33
39
  version: '0'
40
+ segments:
41
+ - 0
34
42
  type: :development
35
43
  prerelease: false
36
- version_requirements: *18946840
44
+ version_requirements: *24510180
37
45
  - !ruby/object:Gem::Dependency
38
46
  name: bundler
39
- requirement: &18946080 !ruby/object:Gem::Requirement
47
+ requirement: &24494060 !ruby/object:Gem::Requirement
40
48
  none: false
41
49
  requirements:
42
- - - ~>
50
+ - - ! '>='
43
51
  - !ruby/object:Gem::Version
44
52
  version: 1.0.0
53
+ segments:
54
+ - 1
55
+ - 0
56
+ - 0
45
57
  type: :development
46
58
  prerelease: false
47
- version_requirements: *18946080
59
+ version_requirements: *24494060
48
60
  - !ruby/object:Gem::Dependency
49
61
  name: jeweler
50
- requirement: &18945200 !ruby/object:Gem::Requirement
62
+ requirement: &24493280 !ruby/object:Gem::Requirement
51
63
  none: false
52
64
  requirements:
53
65
  - - ~>
54
66
  - !ruby/object:Gem::Version
55
67
  version: 1.6.4
68
+ segments:
69
+ - 1
70
+ - 6
71
+ - 4
56
72
  type: :development
57
73
  prerelease: false
58
- version_requirements: *18945200
74
+ version_requirements: *24493280
59
75
  - !ruby/object:Gem::Dependency
60
76
  name: rcov
61
- requirement: &18944220 !ruby/object:Gem::Requirement
77
+ requirement: &24492440 !ruby/object:Gem::Requirement
62
78
  none: false
63
79
  requirements:
64
80
  - - ! '>='
65
81
  - !ruby/object:Gem::Version
66
82
  version: '0'
83
+ segments:
84
+ - 0
67
85
  type: :development
68
86
  prerelease: false
69
- version_requirements: *18944220
87
+ version_requirements: *24492440
70
88
  - !ruby/object:Gem::Dependency
71
89
  name: rspec
72
- requirement: &18943460 !ruby/object:Gem::Requirement
90
+ requirement: &24491780 !ruby/object:Gem::Requirement
73
91
  none: false
74
92
  requirements:
75
93
  - - ! '>='
76
94
  - !ruby/object:Gem::Version
77
95
  version: '0'
96
+ segments:
97
+ - 0
78
98
  type: :development
79
99
  prerelease: false
80
- version_requirements: *18943460
100
+ version_requirements: *24491780
81
101
  - !ruby/object:Gem::Dependency
82
102
  name: ZenTest
83
- requirement: &18928680 !ruby/object:Gem::Requirement
103
+ requirement: &24491040 !ruby/object:Gem::Requirement
84
104
  none: false
85
105
  requirements:
86
106
  - - ! '>='
87
107
  - !ruby/object:Gem::Version
88
108
  version: '0'
109
+ segments:
110
+ - 0
89
111
  type: :development
90
112
  prerelease: false
91
- version_requirements: *18928680
113
+ version_requirements: *24491040
92
114
  - !ruby/object:Gem::Dependency
93
115
  name: autotest-growl
94
- requirement: &18927540 !ruby/object:Gem::Requirement
116
+ requirement: &24490380 !ruby/object:Gem::Requirement
95
117
  none: false
96
118
  requirements:
97
119
  - - ! '>='
98
120
  - !ruby/object:Gem::Version
99
121
  version: '0'
122
+ segments:
123
+ - 0
100
124
  type: :development
101
125
  prerelease: false
102
- version_requirements: *18927540
126
+ version_requirements: *24490380
103
127
  - !ruby/object:Gem::Dependency
104
128
  name: ruby_events
105
- requirement: &18921320 !ruby/object:Gem::Requirement
129
+ requirement: &24489660 !ruby/object:Gem::Requirement
106
130
  none: false
107
131
  requirements:
108
132
  - - ! '>='
109
133
  - !ruby/object:Gem::Version
110
134
  version: '0'
135
+ segments:
136
+ - 0
111
137
  type: :runtime
112
138
  prerelease: false
113
- version_requirements: *18921320
139
+ version_requirements: *24489660
114
140
  description: PubSub pattern
115
141
  email: maxkazargm@gmail.com
116
142
  executables: []
@@ -123,6 +149,7 @@ files:
123
149
  - .document
124
150
  - .rspec
125
151
  - Gemfile
152
+ - Gemfile.lock
126
153
  - LICENSE.txt
127
154
  - README.rdoc
128
155
  - Rakefile
@@ -138,7 +165,7 @@ has_rdoc: true
138
165
  homepage: http://github.com/maxkazar/pubsub
139
166
  licenses:
140
167
  - MIT
141
- post_install_message:
168
+ post_install_message: !!null
142
169
  rdoc_options: []
143
170
  require_paths:
144
171
  - lib
@@ -150,17 +177,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
177
  version: '0'
151
178
  segments:
152
179
  - 0
153
- hash: -2541202216032154175
180
+ hash: -2395597313828472709
154
181
  required_rubygems_version: !ruby/object:Gem::Requirement
155
182
  none: false
156
183
  requirements:
157
184
  - - ! '>='
158
185
  - !ruby/object:Gem::Version
159
186
  version: '0'
187
+ segments:
188
+ - 0
160
189
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 1.6.2
163
- signing_key:
190
+ rubyforge_project: !!null
191
+ rubygems_version: 1.3.7
192
+ signing_key: !!null
164
193
  specification_version: 3
165
194
  summary: PubSub pattern
166
195
  test_files: []