moc 2.5.0.4 → 2.5.0.5

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.
@@ -33,8 +33,8 @@ class Controller
33
33
  def initialize (path = '~/.moc/socket2')
34
34
  @path = File.expand_path(path)
35
35
  @socket = UNIXSocket.new(@path)
36
-
37
- @events = Hash.new { |h, k| h[k] = [] }
36
+
37
+ @queue = []
38
38
  end
39
39
 
40
40
  def respond_to_missing? (id, include_private = false)
@@ -170,37 +170,35 @@ class Controller
170
170
  end
171
171
  }
172
172
 
173
- def on (event = nil, &block)
174
- @events[event ? nil : event.to_sym.upcase] << block
173
+ def looping?; !!@looping; end
175
174
 
176
- self
177
- end
175
+ def loop (&block)
176
+ raise ArgumentError, 'no block given' unless block
178
177
 
179
- def fire (event)
180
- name = event.to_sym
178
+ raise 'already looping' if looping?
181
179
 
182
- @events[nil].each {|block|
183
- block.call(event)
184
- }
180
+ @looping = true
185
181
 
186
- @events[name].each {|block|
187
- block.call(event)
188
- }
182
+ send_command :send_events
189
183
 
190
- self
191
- end
192
-
193
- def loop
194
184
  while event = read_event
195
- fire event
185
+ block.call event
186
+
187
+ until @queue.empty?
188
+ block.call @queue.first
189
+
190
+ @queue.shift
191
+ end
196
192
  end
197
193
 
198
194
  self
195
+ ensure
196
+ @looping = false
199
197
  end
200
198
 
201
199
  def wait_for (name)
202
200
  while (event = read_event) != name
203
- fire event
201
+ @queue << event if looping?
204
202
  end
205
203
 
206
204
  event
@@ -220,6 +218,22 @@ class Controller
220
218
  self
221
219
  end
222
220
 
221
+ def lock
222
+ send_command :lock
223
+ end
224
+
225
+ def unlock
226
+ send_command :unlock
227
+ end
228
+
229
+ def synchronize (&block)
230
+ lock
231
+
232
+ block.call
233
+ ensure
234
+ unlock
235
+ end
236
+
223
237
  def toggle
224
238
  @toggle ||= Toggle.new(self)
225
239
  end
@@ -73,11 +73,11 @@ class Status
73
73
  }
74
74
 
75
75
  def duration
76
- tags.time
76
+ tags.time if tags
77
77
  end
78
78
 
79
79
  def inspect
80
- "#<#{self.class.name}: track=#{track} title=#{title.inspect} artist=#{artist.inspect} album=#{album.inspect} channels=#{channels} bitrate=#{bitrate}(#{average_bitrate}) position=#{position}/#{duration}>"
80
+ "#<#{self.class.name}: track=#{track} title=#{title.inspect} artist=#{artist.inspect} album=#{album.inspect} channels=#{channels} bitrate=#{bitrate}(#{average_bitrate}) position=#{position}/#{duration || ??}>"
81
81
  end
82
82
  end
83
83
 
@@ -137,11 +137,11 @@ class Status
137
137
  }
138
138
 
139
139
  def duration
140
- tags.time
140
+ tags.time if tags
141
141
  end
142
142
 
143
143
  def inspect
144
- "#<#{self.class.name}: track=#{track} title=#{title.inspect} artist=#{artist.inspect} album=#{album.inspect} channels=#{channels} bitrate=#{bitrate}(#{average_bitrate}) position=#{position}/#{duration}>"
144
+ "#<#{self.class.name}: track=#{track} title=#{title.inspect} artist=#{artist.inspect} album=#{album.inspect} channels=#{channels} bitrate=#{bitrate}(#{average_bitrate}) position=#{position}/#{duration || ??}>"
145
145
  end
146
146
  end
147
147
 
@@ -25,7 +25,7 @@ class Symbol
25
25
  @internal = value.respond_to?(:to_i) ? self.class.codes.key(value.to_i) : value.to_sym.upcase
26
26
 
27
27
  unless @internal && self.class.codes.member?(@internal)
28
- raise ArgumentError, 'invalid symbol'
28
+ raise ArgumentError, "invalid symbol #{value}"
29
29
  end
30
30
  end
31
31
 
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Moc
12
12
  def self.version
13
- '2.5.0.4'
13
+ '2.5.0.5'
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0.4
4
+ version: 2.5.0.5
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-06-23 00:00:00.000000000 Z
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: meh@paranoici.org