wabur 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +106 -15
  3. data/bin/wabur +6 -0
  4. data/export/assets/js/ui.js +18 -0
  5. data/lib/wab.rb +7 -1
  6. data/lib/wab/client.rb +145 -0
  7. data/lib/wab/controller.rb +1 -1
  8. data/lib/wab/errors.rb +6 -0
  9. data/lib/wab/impl.rb +1 -1
  10. data/lib/wab/impl/agoo.rb +18 -0
  11. data/lib/wab/impl/agoo/export_proxy.rb +55 -0
  12. data/lib/wab/impl/agoo/handler.rb +51 -0
  13. data/lib/wab/impl/agoo/sender.rb +50 -0
  14. data/lib/wab/impl/agoo/server.rb +59 -0
  15. data/lib/wab/impl/agoo/tql_handler.rb +35 -0
  16. data/lib/wab/impl/model.rb +8 -1
  17. data/lib/wab/impl/rack_error.rb +27 -0
  18. data/lib/wab/impl/rack_handler.rb +69 -0
  19. data/lib/wab/impl/shell.rb +56 -51
  20. data/lib/wab/impl/sinatra.rb +18 -0
  21. data/lib/wab/impl/sinatra/export_proxy.rb +57 -0
  22. data/lib/wab/impl/sinatra/handler.rb +50 -0
  23. data/lib/wab/impl/sinatra/sender.rb +53 -0
  24. data/lib/wab/impl/sinatra/server.rb +66 -0
  25. data/lib/wab/impl/sinatra/tql_handler.rb +35 -0
  26. data/lib/wab/impl/templates/wabur.conf.template +1 -1
  27. data/lib/wab/impl/webrick.rb +18 -0
  28. data/lib/wab/impl/webrick/export_proxy.rb +41 -0
  29. data/lib/wab/impl/webrick/handler.rb +116 -0
  30. data/lib/wab/impl/webrick/sender.rb +34 -0
  31. data/lib/wab/impl/webrick/server.rb +39 -0
  32. data/lib/wab/impl/webrick/tql_handler.rb +58 -0
  33. data/lib/wab/racker.rb +25 -0
  34. data/lib/wab/version.rb +1 -1
  35. data/pages/Architecture.md +15 -6
  36. data/test/test_client.rb +282 -0
  37. data/test/test_impl.rb +2 -0
  38. data/test/test_runner.rb +267 -91
  39. metadata +27 -5
  40. data/lib/wab/impl/export_proxy.rb +0 -39
  41. data/lib/wab/impl/handler.rb +0 -98
@@ -1,39 +0,0 @@
1
-
2
- require 'webrick'
3
-
4
- module WAB
5
- module Impl
6
-
7
- # A handler that provides missing files in an assets directory where the
8
- # files are the wab and wab UI files.
9
- class ExportProxy < WEBrick::HTTPServlet::FileHandler
10
-
11
- def initialize(server, path)
12
- super
13
- end
14
-
15
- def do_GET(req, res)
16
- super
17
- rescue Exception => e
18
- path = req.path
19
- path = '/index.html' if '/' == path
20
- begin
21
- mime = nil
22
- index = path.rindex('.')
23
- unless index.nil?
24
- mime = WEBrick::HTTPUtils::DefaultMimeTypes[path[index + 1..-1]]
25
- end
26
- mime = 'text/plain' if mime.nil?
27
- content = WAB.get_export(path)
28
- res.status = 200
29
- res['Content-Type'] = mime
30
- res.body = content
31
- rescue Exception
32
- # raise the original error for a normal not found error
33
- raise e
34
- end
35
- end
36
-
37
- end # ExportProxy
38
- end # Impl
39
- end # WAB
@@ -1,98 +0,0 @@
1
-
2
- require 'webrick'
3
-
4
- module WAB
5
- module Impl
6
-
7
- # Handler for requests that fall under the path assigned to the
8
- # Controller. This is used only with the WAB::Impl::Shell.
9
- class Handler < WEBrick::HTTPServlet::AbstractServlet
10
-
11
- def initialize(server, shell)
12
- super(server)
13
- @shell = shell
14
- end
15
-
16
- def do_GET(req, res)
17
- controller, path, query = extract_req(req)
18
- log_request('controller.read', path, query) if @shell.logger.info?
19
- send_result(controller.read(path, query), res, path, query)
20
- rescue StandardError => e
21
- send_error(e, res)
22
- end
23
-
24
- def do_PUT(req, res)
25
- controller, path, query, body = extract_req(req)
26
- log_request_with_body('controller.create', path, query, body) if @shell.logger.info?
27
- send_result(controller.create(path, query, body), res, path, query)
28
- rescue StandardError => e
29
- send_error(e, res)
30
- end
31
-
32
- def do_POST(req, res)
33
- controller, path, query, body = extract_req(req)
34
- log_request_with_body('controller.update', path, query, body) if @shell.logger.info?
35
- send_result(controller.update(path, query, body), res, path, query)
36
- rescue StandardError => e
37
- send_error(e, res)
38
- end
39
-
40
- def do_DELETE(req, res)
41
- controller, path, query = extract_req(req)
42
- log_request('controller.delete', path, query) if @shell.logger.info?
43
- send_result(controller.delete(path, query), res, path, query)
44
- rescue StandardError => e
45
- send_error(e, res)
46
- end
47
-
48
- private
49
-
50
- def log_request(caller, path, query)
51
- @shell.logger.info("#{caller}(#{path.join('/')}#{query})")
52
- end
53
-
54
- def log_request_with_body(caller, path, query, body)
55
- @shell.logger.info("#{caller} #{path.join('/')}#{query}\n#{body.json(@shell.indent)}")
56
- end
57
-
58
- # Pulls and converts the request path, query, and body. Also returns the
59
- # controller.
60
- def extract_req(req)
61
- path = req.path.split('/')[1..-1]
62
- query = {}
63
- req.query.each { |k,v| query[k.to_sym] = v }
64
- request_body = req.body
65
- if request_body.nil?
66
- body = nil
67
- else
68
- body = Data.new(
69
- Oj.strict_load(request_body, symbol_keys: true)
70
- )
71
- body.detect
72
- end
73
- [@shell.path_controller(path), path, query, body]
74
- end
75
-
76
- # Sends the results from a controller request.
77
- def send_result(result, res, path, query)
78
- result = @shell.data(result) unless result.is_a?(WAB::Data)
79
- response_body = result.json(@shell.indent)
80
- res.status = 200
81
- res['Content-Type'] = 'application/json'
82
- @shell.logger.debug("reply to #{path.join('/')}#{query}: #{response_body}") if @shell.logger.debug?
83
- res.body = response_body
84
- end
85
-
86
- # Sends an error from a rescued call.
87
- def send_error(e, res)
88
- res.status = 500
89
- res['Content-Type'] = 'application/json'
90
- body = { code: -1, error: "#{e.class}: #{e.message}" }
91
- body[:backtrace] = e.backtrace
92
- res.body = @shell.data(body).json(@shell.indent)
93
- @shell.logger.warn(Impl.format_error(e))
94
- end
95
-
96
- end # Handler
97
- end # Impl
98
- end # WAB