simplews 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/start_ws +1 -3
- data/lib/simplews.rb +80 -19
- data/lib/simplews/jobs.rb +11 -19
- data/lib/simplews/rake.rb +2 -0
- metadata +1 -1
data/bin/start_ws
CHANGED
@@ -36,9 +36,7 @@ server = SimpleWS.new(options[:name], options[:description], options[:host], opt
|
|
36
36
|
eval actions
|
37
37
|
end
|
38
38
|
|
39
|
-
if options[:wsdl]
|
40
|
-
File.open(options[:wsdl], 'w') do |f| f.write server.wsdl end
|
41
|
-
end
|
39
|
+
server.wsdl(options[:wsdl]) if options[:wsdl]
|
42
40
|
|
43
41
|
trap('INT'){
|
44
42
|
puts "Stopping server"
|
data/lib/simplews.rb
CHANGED
@@ -49,7 +49,7 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
49
49
|
VERSION = "1.3.6"
|
50
50
|
|
51
51
|
# Saves method defined in the class to be served by the instances
|
52
|
-
|
52
|
+
INHERITED_METHODS = {}
|
53
53
|
|
54
54
|
# This is a helper function for clients. Given the +url+ where the
|
55
55
|
# server is listening, as well as the name of the server, it can
|
@@ -102,17 +102,27 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
102
102
|
@messages = []
|
103
103
|
@operations = []
|
104
104
|
@bindings = []
|
105
|
+
@method_descriptions = {}
|
106
|
+
@method_order = []
|
105
107
|
|
106
108
|
if block_given?
|
107
109
|
instance_eval &block
|
108
110
|
end
|
109
111
|
|
110
112
|
puts "Server #{ name } at #{ host }:#{ port }"
|
111
|
-
|
113
|
+
|
114
|
+
|
112
115
|
desc "Return the WSDL describing the web server"
|
113
116
|
param_desc :return => "WSDL description"
|
114
117
|
serve :wsdl, %w(), :return => :string
|
115
|
-
|
118
|
+
|
119
|
+
desc "Return HMLT table with documentation for the web service"
|
120
|
+
param_desc :return => "HTML table with documentation"
|
121
|
+
serve :documentation, %w(), :return => :string
|
122
|
+
|
123
|
+
INHERITED_METHODS.each{|name, info|
|
124
|
+
@@last_description = info[:description]
|
125
|
+
@@last_param_description = info[:param_descriptions]
|
116
126
|
serve name, info[:args], info[:types], &info[:block]
|
117
127
|
}
|
118
128
|
end
|
@@ -126,8 +136,6 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
126
136
|
# Add a description for the next method served.
|
127
137
|
@@last_description = nil
|
128
138
|
@@last_param_description = nil
|
129
|
-
STEP_DESCRIPTIONS = {}
|
130
|
-
PARAMETER_DESCRIPTIONS = {}
|
131
139
|
def desc(text = "")
|
132
140
|
@@last_description = text
|
133
141
|
end
|
@@ -164,10 +172,14 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
164
172
|
# method is taken to return no value. Other than that, if a parameter
|
165
173
|
# type is omitted it is taken to be :string.
|
166
174
|
def serve(name, args=[], types={}, &block)
|
167
|
-
|
168
|
-
|
175
|
+
|
176
|
+
@method_descriptions[name] = {:args => args, :types => types, :block => block,
|
177
|
+
:description => @@last_description, :param_descriptions => @@last_param_description}
|
178
|
+
|
169
179
|
@@last_description = nil
|
170
180
|
@@last_param_description = nil
|
181
|
+
|
182
|
+
@method_order << name
|
171
183
|
if block
|
172
184
|
inline_name = "_inline_" + name.to_s
|
173
185
|
add_to_ruby(inline_name, &block)
|
@@ -185,11 +197,10 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
185
197
|
# instance check if there where any methods declared to be served in the class
|
186
198
|
# and add them.
|
187
199
|
def self.serve(name, args=[], types={}, &block)
|
188
|
-
|
189
|
-
|
200
|
+
INHERITED_METHODS[name] = {:args => args, :types => types, :block => block,
|
201
|
+
:description => @@last_description, :param_descriptions => @@last_param_description}
|
190
202
|
@@last_description = nil
|
191
203
|
@@last_param_description = nil
|
192
|
-
METHODS[name] = {:args => args, :types => types, :block => block}
|
193
204
|
end
|
194
205
|
|
195
206
|
# If +filename+ is specified it saves the +WSDL+ file in that file. If
|
@@ -215,6 +226,47 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
215
226
|
end
|
216
227
|
end
|
217
228
|
|
229
|
+
def documentation(filename = nil)
|
230
|
+
html_table = Builder::XmlMarkup.new(:indent => 2).table :class => "WS_documentation" do |xml|
|
231
|
+
xml.thead do
|
232
|
+
xml.tr do
|
233
|
+
xml.th "Operation", :class => "WS_operation"
|
234
|
+
xml.th "Parameters", :class => "WS_parameters"
|
235
|
+
xml.th "Documentation", :class => "WS_documentation"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
xml.tbody do
|
239
|
+
@method_order.each do |method|
|
240
|
+
xml.tr do
|
241
|
+
xml.td method.to_s, :class => "WS_operation"
|
242
|
+
|
243
|
+
xml.td :class => "WS_parameters" do
|
244
|
+
description = @method_descriptions[method]
|
245
|
+
method_parameters = description[:args]
|
246
|
+
method_parameters.push 'return' unless description[:types][:return] == false || description[:types]['return'] == false
|
247
|
+
if method_parameters.any?
|
248
|
+
xml.dl :class => "WS_parameter_documentation" do
|
249
|
+
method_parameters.each do |param|
|
250
|
+
xml.dt param
|
251
|
+
if description[:param_descriptions]
|
252
|
+
xml.dd description[:param_descriptions][param.to_s] || ""
|
253
|
+
else
|
254
|
+
xml.dd
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
xml.td description[:description] || "", :class => "WS_documentation"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
html_table
|
268
|
+
end
|
269
|
+
|
218
270
|
private
|
219
271
|
|
220
272
|
def add_to_ruby(name, &block)
|
@@ -222,16 +274,22 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
222
274
|
end
|
223
275
|
|
224
276
|
def add_to_wsdl(name, args, types)
|
277
|
+
description = @method_descriptions[name]
|
225
278
|
message = Builder::XmlMarkup.new(:indent => 2).message :name => "#{ name }Request" do |xml|
|
226
|
-
|
279
|
+
|
280
|
+
args.each do |param|
|
227
281
|
type = types[param.to_s] || types[param.to_sym] || :string
|
228
282
|
type = type.to_sym
|
283
|
+
|
229
284
|
xml.part :name => param, :type => TYPES2WSDL[type] do
|
230
|
-
|
231
|
-
|
285
|
+
param_descriptions = description[:param_descriptions]
|
286
|
+
|
287
|
+
if param_descriptions && param_descriptions[param.to_s]
|
288
|
+
xml.documentation param_descriptions[param.to_s]
|
232
289
|
end
|
233
290
|
end
|
234
|
-
|
291
|
+
|
292
|
+
end
|
235
293
|
end
|
236
294
|
@messages << message
|
237
295
|
|
@@ -240,17 +298,21 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
240
298
|
type = :string if type.nil?
|
241
299
|
if type
|
242
300
|
type = type.to_sym
|
301
|
+
|
243
302
|
xml.part :name => 'return', :type => TYPES2WSDL[type] do
|
244
|
-
|
245
|
-
|
303
|
+
param_descriptions = description[:param_descriptions]
|
304
|
+
|
305
|
+
if param_descriptions && param_descriptions['return']
|
306
|
+
xml.documentation param_descriptions['return']
|
246
307
|
end
|
247
308
|
end
|
309
|
+
|
248
310
|
end
|
249
311
|
end
|
250
312
|
@messages << message
|
251
313
|
|
252
314
|
operation = Builder::XmlMarkup.new(:indent => 2).operation :name => "#{ name }" do |xml|
|
253
|
-
xml.documentation
|
315
|
+
xml.documentation description[:description] if description[:description]
|
254
316
|
xml.input :message => "tns:#{ name }Request"
|
255
317
|
xml.output :message => "tns:#{ name }Response"
|
256
318
|
end
|
@@ -268,9 +330,8 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
268
330
|
end
|
269
331
|
|
270
332
|
@bindings << binding
|
271
|
-
|
272
333
|
end
|
273
|
-
|
334
|
+
|
274
335
|
|
275
336
|
WSDL_STUB =<<EOT
|
276
337
|
<?xml version="1.0"?>
|
data/lib/simplews/jobs.rb
CHANGED
@@ -18,6 +18,8 @@ class SimpleWS::Jobs < SimpleWS
|
|
18
18
|
:job_info => 1,
|
19
19
|
:monitor => 2,
|
20
20
|
}
|
21
|
+
|
22
|
+
INHERITED_TASKS = {}
|
21
23
|
|
22
24
|
|
23
25
|
#{{{ Scheduler
|
@@ -366,12 +368,8 @@ class SimpleWS::Jobs < SimpleWS
|
|
366
368
|
end
|
367
369
|
|
368
370
|
def task(name, params=[], types={}, results = [], &block)
|
369
|
-
|
370
|
-
|
371
|
-
@@last_description = nil
|
372
|
-
@@last_param_description = nil
|
373
|
-
PARAMETER_DESCRIPTIONS[name.to_s]['return'] ||= 'Job identifier' if PARAMETER_DESCRIPTIONS[name.to_s]
|
374
|
-
|
371
|
+
@@last_param_description['return'] ||= 'Job identifier' if @@last_param_description
|
372
|
+
|
375
373
|
Scheduler.task name, results, block
|
376
374
|
serve name.to_s, params + ['suggested_name'], types.merge(:suggested_name => 'string', :return => :string) do |*args|
|
377
375
|
Scheduler.run name, *args
|
@@ -380,17 +378,11 @@ class SimpleWS::Jobs < SimpleWS
|
|
380
378
|
|
381
379
|
@@tasks = {}
|
382
380
|
def self.task(name, params=[], types={}, results =[], &block)
|
383
|
-
|
384
|
-
|
381
|
+
INHERITED_TASKS[name] = {:params => params, :types => types, :results => results, :block => block,
|
382
|
+
:description => @@last_description, :param_description => @@last_param_description};
|
383
|
+
|
385
384
|
@@last_description = nil
|
386
385
|
@@last_param_description = nil
|
387
|
-
if PARAMETER_DESCRIPTIONS[name.to_s]
|
388
|
-
PARAMETER_DESCRIPTIONS[name.to_s]['return'] ||= 'Job identifier'
|
389
|
-
PARAMETER_DESCRIPTIONS[name.to_s]['suggested_name'] ||= 'Suggested name for the job'
|
390
|
-
end
|
391
|
-
|
392
|
-
Scheduler.task name, results, block
|
393
|
-
@@tasks[name] = {:params => params, :types => types};
|
394
386
|
end
|
395
387
|
|
396
388
|
def abort_jobs
|
@@ -408,10 +400,10 @@ class SimpleWS::Jobs < SimpleWS
|
|
408
400
|
@workdir = workdir || "/tmp/#{ name }"
|
409
401
|
Scheduler.workdir = @workdir
|
410
402
|
@results = {}
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
403
|
+
INHERITED_TASKS.each{|task,info|
|
404
|
+
@@last_description = info[:description]
|
405
|
+
@@last_param_description = info[:param_description]
|
406
|
+
task(task, info[:params], info[:types], info[:results], &info[:block])
|
415
407
|
}
|
416
408
|
|
417
409
|
|
data/lib/simplews/rake.rb
CHANGED