eventmachine-distributed-notification 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -9,6 +9,7 @@
9
9
  @property (assign) VALUE handler;
10
10
 
11
11
  -(void)observe;
12
+ -(void)unobserve;
12
13
 
13
14
  @end
14
15
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  - (void)dealloc
13
13
  {
14
- [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
14
+ [self unobserve];
15
15
  [name release];
16
16
  [super dealloc];
17
17
  }
@@ -26,6 +26,11 @@
26
26
  ];
27
27
  }
28
28
 
29
+ - (void)unobserve
30
+ {
31
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
32
+ }
33
+
29
34
  - (void)notify:(NSNotification *)theNotification
30
35
  {
31
36
  VALUE aName = rb_str_new2([[theNotification name] UTF8String]);
@@ -118,7 +123,6 @@ static VALUE cObserverNative_new(int argc, VALUE *argv, VALUE klass)
118
123
  }
119
124
 
120
125
  [obs setHandler:handler];
121
- [obs observe];
122
126
 
123
127
  [pool release];
124
128
 
@@ -139,6 +143,24 @@ static VALUE cObserverNative_run_forever(int argc, VALUE *argv, VALUE self)
139
143
  return Qnil;
140
144
  }
141
145
 
146
+ static VALUE cObserverNative_observe(int argc, VALUE *argv, VALUE self)
147
+ {
148
+ Observer *obs = getObserver(self);
149
+
150
+ [obs observe];
151
+
152
+ return Qnil;
153
+ }
154
+
155
+ static VALUE cObserverNative_unobserve(int argc, VALUE *argv, VALUE self)
156
+ {
157
+ Observer *obs = getObserver(self);
158
+
159
+ [obs unobserve];
160
+
161
+ return Qnil;
162
+ }
163
+
142
164
  void Init_observer_native(void){
143
165
  VALUE rb_mEventMachine, rb_mDistributedNotification;
144
166
 
@@ -148,4 +170,6 @@ void Init_observer_native(void){
148
170
  rb_define_singleton_method(rb_cObserverNative, "new", cObserverNative_new, -1);
149
171
  rb_define_method(rb_cObserverNative, "run", cObserverNative_run, -1);
150
172
  rb_define_method(rb_cObserverNative, "run_forever", cObserverNative_run_forever, -1);
173
+ rb_define_method(rb_cObserverNative, "observe", cObserverNative_observe, -1);
174
+ rb_define_method(rb_cObserverNative, "unobserve", cObserverNative_unobserve, -1);
151
175
  }
@@ -24,12 +24,14 @@ module EventMachine
24
24
  end
25
25
 
26
26
  def start
27
+ @observer.observe
27
28
  @timer = EventMachine::add_periodic_timer(1) do
28
29
  @observer.run
29
30
  end
30
31
  end
31
32
 
32
33
  def stop
34
+ @observer.unobserve
33
35
  @timer.cancel if @timer
34
36
  end
35
37
  end
@@ -24,6 +24,7 @@ describe EventMachine::DistributedNotification::Poster do
24
24
  EM::add_timer(1) {
25
25
  EM::post_distributed_notification('xxx', 'yyy')
26
26
  EM.stop
27
+ watcher.stop
27
28
  }
28
29
  }
29
30
 
@@ -37,8 +38,8 @@ describe EventMachine::DistributedNotificationWatch do
37
38
  itunes.stop
38
39
 
39
40
  context 'instantiate' do
40
- it 'should observe distributed notifications' do
41
- watcher = Watcher.new(nil)
41
+ it 'should watch distributed notifications' do
42
+ watcher = Watcher.new('com.apple.iTunes.playerInfo')
42
43
 
43
44
  EM.run {
44
45
  watcher.start
@@ -48,6 +49,7 @@ describe EventMachine::DistributedNotificationWatch do
48
49
  EM::add_timer(1) {
49
50
  itunes.stop
50
51
  EM.stop
52
+ watcher.stop
51
53
  }
52
54
  }
53
55
 
@@ -57,21 +59,24 @@ describe EventMachine::DistributedNotificationWatch do
57
59
  end
58
60
 
59
61
  context 'invoked from EM.watch_distributed_notification' do
60
- it 'should observe distributed notifications from ' do
61
- watcher = nil
62
+ context 'with class' do
63
+ it 'should watch distributed notifications' do
64
+ watcher = nil
62
65
 
63
- EM.run {
64
- watcher = EM.watch_distributed_notification(nil, Watcher)
66
+ EM.run {
67
+ watcher = EM.watch_distributed_notification(nil, Watcher)
65
68
 
66
- itunes.playlists["Music"].tracks[1].play
69
+ itunes.playlists["Music"].tracks[1].play
67
70
 
68
- EM::add_timer(1) {
69
- itunes.stop
70
- EM.stop
71
+ EM::add_timer(1) {
72
+ itunes.stop
73
+ EM.stop
74
+ watcher.stop
75
+ }
71
76
  }
72
- }
73
77
 
74
- watcher.value.should_not be_nil
78
+ watcher.value.should_not be_nil
79
+ end
75
80
  end
76
81
  end
77
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-distributed-notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70278625507360 !ruby/object:Gem::Requirement
16
+ requirement: &70178503276700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70278625507360
24
+ version_requirements: *70178503276700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70278625505040 !ruby/object:Gem::Requirement
27
+ requirement: &70178503273500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70278625505040
35
+ version_requirements: *70178503273500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &70278625517900 !ruby/object:Gem::Requirement
38
+ requirement: &70178503287000 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70278625517900
46
+ version_requirements: *70178503287000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70278625514980 !ruby/object:Gem::Requirement
49
+ requirement: &70178503284120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70278625514980
57
+ version_requirements: *70178503284120
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70278625511060 !ruby/object:Gem::Requirement
60
+ requirement: &70178503280260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70278625511060
68
+ version_requirements: *70178503280260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rb-appscript
71
- requirement: &70278625526100 !ruby/object:Gem::Requirement
71
+ requirement: &70178503295420 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70278625526100
79
+ version_requirements: *70178503295420
80
80
  description: An EventMachine extension to watch OSX's Distributed Notification, posted
81
81
  by iTunes etc.
82
82
  email: youpy@buycheapviagraonlinenow.com
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: 3735464898048564235
126
+ hash: -1517368430001229274
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements: