ruby_fs 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # develop
2
2
 
3
+ # 0.3.0
4
+ * Feature/Change: Switch command methods from yielding the result asynchronously to returning it synchronously. Allows for better actor usage (async/futures)
5
+
3
6
  # 0.2.0
4
7
  * Feature: Common command helper methods
5
8
  * Feature: Trace level logging & easy logging override
@@ -55,16 +55,17 @@ module RubyFS
55
55
  # @param [#to_s] command the command to run
56
56
  # @param [optional, Hash] options the command's options, where keys have _ substituted for -
57
57
  #
58
- # @yield [response] Handle the command's response
59
- # @yieldparam [RubyFS::Response] response the command's response object
60
- def command(command, options = {}, &block)
61
- @command_callbacks << (block || lambda { |reply| logger.debug "Reply to a command (#{command}) without a callback: #{reply.inspect}" })
58
+ # @return [RubyFS::Response] response the command's response object
59
+ def command(command, options = {}, &callback)
60
+ uuid = SecureRandom.uuid
61
+ @command_callbacks << (callback || lambda { |reply| signal uuid, reply })
62
62
  string = "#{command}\n"
63
63
  options.each_pair do |key, value|
64
64
  string << "#{key.to_s.gsub '_', '-'}: #{value}\n" if value
65
65
  end
66
66
  string << "\n"
67
67
  send_data string
68
+ wait uuid unless callback
68
69
  end
69
70
 
70
71
  #
@@ -72,10 +73,9 @@ module RubyFS
72
73
  #
73
74
  # @param [#to_s] action the API action to execute
74
75
  #
75
- # @yield [response] Handle the command's response
76
- # @yieldparam [RubyFS::Response] response the command's response object
77
- def api(action, &block)
78
- command "api #{action}", &block
76
+ # @return [RubyFS::Response] response the command's response object
77
+ def api(action)
78
+ command "api #{action}"
79
79
  end
80
80
 
81
81
  #
@@ -83,10 +83,9 @@ module RubyFS
83
83
  #
84
84
  # @param [#to_s] action the API action to execute
85
85
  #
86
- # @yield [response] Handle the command's response
87
- # @yieldparam [RubyFS::Response] response the command's response object
88
- def bgapi(action, &block)
89
- command "bgapi #{action}", &block
86
+ # @return [RubyFS::Response] response the command's response object
87
+ def bgapi(action)
88
+ command "bgapi #{action}"
90
89
  end
91
90
 
92
91
  #
@@ -95,10 +94,9 @@ module RubyFS
95
94
  # @param [#to_s] call the call ID to send the message to
96
95
  # @param [optional, Hash] options the message options
97
96
  #
98
- # @yield [response] Handle the message's response
99
- # @yieldparam [RubyFS::Response] response the message's response object
100
- def sendmsg(call, options = {}, &block)
101
- command "SendMsg #{call}", options, &block
97
+ # @return [RubyFS::Response] response the message's response object
98
+ def sendmsg(call, options = {})
99
+ command "SendMsg #{call}", options
102
100
  end
103
101
 
104
102
  #
@@ -108,10 +106,9 @@ module RubyFS
108
106
  # @param [#to_s] appname the app to execute
109
107
  # @param [optional, String] options the application options
110
108
  #
111
- # @yield [response] Handle the application's response
112
- # @yieldparam [RubyFS::Response] response the application's response object
113
- def application(call, appname, options = nil, &block)
114
- sendmsg call, :call_command => 'execute', :execute_app_name => appname, :execute_app_arg => options, &block
109
+ # @return [RubyFS::Response] response the application's response object
110
+ def application(call, appname, options = nil)
111
+ sendmsg call, :call_command => 'execute', :execute_app_name => appname, :execute_app_arg => options
115
112
  end
116
113
 
117
114
  #
@@ -162,7 +159,7 @@ module RubyFS
162
159
  @command_callbacks.pop.call CommandReply.new(headers)
163
160
  when 'auth/request'
164
161
  command "auth #{@secret}" do
165
- command "event json ALL" if @events
162
+ command! "event json ALL" if @events
166
163
  end
167
164
  else
168
165
  raise "Unknown request type received (#{headers.inspect})"
@@ -1,3 +1,3 @@
1
1
  module RubyFS
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -132,25 +132,11 @@ Content-Type: text/event-json
132
132
  ]
133
133
  end
134
134
 
135
- it "can send commands with response callbacks" do
135
+ it "can send commands and returns the response" do
136
136
  expect_connected_event
137
137
  expect_disconnected_event
138
- handler = mock
139
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
140
- mocked_server(1, lambda { |server| @stream.command('foo') { |reply| handler.call reply } }) do |val, server|
141
- val.should == "foo\n\n"
142
- server.send_data %Q(
143
- Content-Type: command/reply
144
- Reply-Text: +OK accepted
145
-
146
- )
147
- end
148
- end
149
-
150
- it "can send commands without response callbacks" do
151
- expect_connected_event
152
- expect_disconnected_event
153
- mocked_server(1, lambda { |server| @stream.command 'foo' }) do |val, server|
138
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
139
+ mocked_server(1, lambda { |server| @stream.command('foo').should == reply }) do |val, server|
154
140
  val.should == "foo\n\n"
155
141
  server.send_data %Q(
156
142
  Content-Type: command/reply
@@ -163,7 +149,7 @@ Reply-Text: +OK accepted
163
149
  it "can send commands with options" do
164
150
  expect_connected_event
165
151
  expect_disconnected_event
166
- mocked_server(1, lambda { |server| @stream.command 'foo', :one => 1, :foo_bar => :doo_dah }) do |val, server|
152
+ mocked_server(1, lambda { |server| @stream.command! 'foo', :one => 1, :foo_bar => :doo_dah }) do |val, server|
167
153
  val.should == %Q(foo
168
154
  one: 1
169
155
  foo-bar: doo_dah
@@ -172,12 +158,11 @@ foo-bar: doo_dah
172
158
  end
173
159
  end
174
160
 
175
- it "can send API commands with response callbacks" do
161
+ it "can send API commands and returns the response" do
176
162
  expect_connected_event
177
163
  expect_disconnected_event
178
- handler = mock
179
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
180
- mocked_server(1, lambda { |server| @stream.api('foo') { |reply| handler.call reply } }) do |val, server|
164
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
165
+ mocked_server(1, lambda { |server| @stream.api('foo').should == reply }) do |val, server|
181
166
  val.should == "api foo\n\n"
182
167
  server.send_data %Q(
183
168
  Content-Type: command/reply
@@ -187,12 +172,11 @@ Reply-Text: +OK accepted
187
172
  end
188
173
  end
189
174
 
190
- it "can send background API commands with response callbacks" do
175
+ it "can send background API commands and returns the response" do
191
176
  expect_connected_event
192
177
  expect_disconnected_event
193
- handler = mock
194
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK Job-UUID: 4e8344be-c1fe-11e1-a7bf-cf9911a69d1e', :job_uuid => '4e8344be-c1fe-11e1-a7bf-cf9911a69d1e')
195
- mocked_server(1, lambda { |server| @stream.bgapi('foo') { |reply| handler.call reply } }) do |val, server|
178
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK Job-UUID: 4e8344be-c1fe-11e1-a7bf-cf9911a69d1e', :job_uuid => '4e8344be-c1fe-11e1-a7bf-cf9911a69d1e')
179
+ mocked_server(1, lambda { |server| @stream.bgapi('foo').should == reply }) do |val, server|
196
180
  val.should == "bgapi foo\n\n"
197
181
  server.send_data %Q(
198
182
  Content-Type: command/reply
@@ -203,12 +187,11 @@ Job-UUID: 4e8344be-c1fe-11e1-a7bf-cf9911a69d1e
203
187
  end
204
188
  end
205
189
 
206
- it "can send messages to calls with options and response callbacks" do
190
+ it "can send messages to calls with options and returns the response" do
207
191
  expect_connected_event
208
192
  expect_disconnected_event
209
- handler = mock
210
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
211
- mocked_server(1, lambda { |server| @stream.sendmsg('aUUID', :call_command => 'execute') { |reply| handler.call reply } }) do |val, server|
193
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
194
+ mocked_server(1, lambda { |server| @stream.sendmsg('aUUID', :call_command => 'execute').should == reply }) do |val, server|
212
195
  val.should == %Q(SendMsg aUUID
213
196
  call-command: execute
214
197
 
@@ -221,12 +204,11 @@ Reply-Text: +OK accepted
221
204
  end
222
205
  end
223
206
 
224
- it "can execute applications on calls without options but with response callbacks" do
207
+ it "can execute applications on calls without options and returns the response" do
225
208
  expect_connected_event
226
209
  expect_disconnected_event
227
- handler = mock
228
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
229
- mocked_server(1, lambda { |server| @stream.application('aUUID', 'answer') { |reply| handler.call reply } }) do |val, server|
210
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
211
+ mocked_server(1, lambda { |server| @stream.application('aUUID', 'answer').should == reply }) do |val, server|
230
212
  val.should == %Q(SendMsg aUUID
231
213
  call-command: execute
232
214
  execute-app-name: answer
@@ -240,12 +222,11 @@ Reply-Text: +OK accepted
240
222
  end
241
223
  end
242
224
 
243
- it "can execute applications on calls with options and response callbacks" do
225
+ it "can execute applications on calls with options and returns the response" do
244
226
  expect_connected_event
245
227
  expect_disconnected_event
246
- handler = mock
247
- handler.expects(:call).once.with CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
248
- mocked_server(1, lambda { |server| @stream.application('aUUID', 'playback', '/tmp/test.wav') { |reply| handler.call reply } }) do |val, server|
228
+ reply = CommandReply.new(:content_type => 'command/reply', :reply_text => '+OK accepted')
229
+ mocked_server(1, lambda { |server| @stream.application('aUUID', 'playback', '/tmp/test.wav').should == reply }) do |val, server|
249
230
  val.should == %Q(SendMsg aUUID
250
231
  call-command: execute
251
232
  execute-app-name: playback
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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-02 00:00:00.000000000 Z
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uuidtools
@@ -295,7 +295,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
295
295
  version: '0'
296
296
  segments:
297
297
  - 0
298
- hash: 3148609615352772925
298
+ hash: 1007735488205713228
299
299
  required_rubygems_version: !ruby/object:Gem::Requirement
300
300
  none: false
301
301
  requirements:
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
304
  version: '0'
305
305
  segments:
306
306
  - 0
307
- hash: 3148609615352772925
307
+ hash: 1007735488205713228
308
308
  requirements: []
309
309
  rubyforge_project: ruby_fs
310
310
  rubygems_version: 1.8.24