tgauge 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 401d7c55ac6b44246db7f0c26a8568a5ae221c3e
4
- data.tar.gz: 787166488e195d5837e5f1407a4933bb8aff1710
3
+ metadata.gz: 253f30fa85171dd6864075d5031debeff3ef3c81
4
+ data.tar.gz: 9e29cffe94fb981e244fb1ce339428d8e2e22616
5
5
  SHA512:
6
- metadata.gz: 775f299a0058a2da9c81ef18eca6e6e97d6167ce24f4d70e2cd1760660fbbb3398d6b13a061a6df9cc24a45db48306f8bfb3d34edbd2d67a4cf6df5093634ce6
7
- data.tar.gz: a7c1fa59e21f8735e73e5fa630aaaed755c8d409f4c4d824ba7e0062a5e792e6df7add741cf7bf3acd6cf88f7c41d26dcdb29bafdf37f4b4ba5b8660bd2e8f54
6
+ metadata.gz: cc22ef833fdfe91701380846af6a39b47fd4584b4709e58a1b7e474fff9449a6ac0177c7c97ec549e386fb0f68ef35e2cb02008ebdfe9bd6330e632833434f2a
7
+ data.tar.gz: e28dd468782f3e5a8712f3e7668878fa15a2cd0a94325c5d6bad67e9f3b61d48e8eaca224773a2a67265bf4facca63da3a4879381bc8297e5f0f0b0af80df56b
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .byebug_history
11
+ /config/
12
+ /db/
data/lib/db/router.rb CHANGED
@@ -1,74 +1,76 @@
1
- class Route
2
- attr_reader :pattern, :http_method, :controller_class, :action_name
1
+ module TGauge
2
+ class Route
3
+ attr_reader :pattern, :http_method, :controller_class, :action_name
3
4
 
4
- def initialize(pattern, http_method, controller_class, action_name)
5
- @pattern = pattern
6
- @http_method = http_method
7
- @controller_class = controller_class
8
- @action_name = action_name
9
- end
10
-
11
- # checks if pattern matches path and method matches request method
12
- def matches?(req)
13
- (@pattern =~ req.path) == 0 && req.request_method.downcase == @http_method.to_s
14
- end
5
+ def initialize(pattern, http_method, controller_class, action_name)
6
+ @pattern = pattern
7
+ @http_method = http_method
8
+ @controller_class = controller_class
9
+ @action_name = action_name
10
+ end
15
11
 
16
- # use pattern to pull out route params (save for later?)
17
- # instantiate controller and call controller action
18
- def run(req, res)
19
- match_data = @pattern.match(req.path)
20
- route_params = {}
21
- match_data.names.each do |key|
22
- route_params[key] = match_data[key]
12
+ # checks if pattern matches path and method matches request method
13
+ def matches?(req)
14
+ (@pattern =~ req.path) == 0 && req.request_method.downcase == @http_method.to_s
23
15
  end
24
16
 
25
- controller = controller_class.new(req, res, route_params)
26
- controller.invoke_action(@action_name)
17
+ # use pattern to pull out route params (save for later?)
18
+ # instantiate controller and call controller action
19
+ def run(req, res)
20
+ match_data = @pattern.match(req.path)
21
+ route_params = {}
22
+ match_data.names.each do |key|
23
+ route_params[key] = match_data[key]
24
+ end
25
+
26
+ controller = controller_class.new(req, res, route_params)
27
+ controller.invoke_action(@action_name)
28
+ end
27
29
  end
28
- end
29
30
 
30
- class Router
31
- attr_reader :routes
31
+ class Router
32
+ attr_reader :routes
32
33
 
33
- def initialize
34
- @routes = []
35
- end
34
+ def initialize
35
+ @routes = []
36
+ end
36
37
 
37
- # simply adds a new route to the list of routes
38
- def add_route(pattern, method, controller_class, action_name)
39
- @routes << Route.new(pattern, method, controller_class, action_name)
40
- end
38
+ # simply adds a new route to the list of routes
39
+ def add_route(pattern, method, controller_class, action_name)
40
+ @routes << Route.new(pattern, method, controller_class, action_name)
41
+ end
41
42
 
42
- # evaluate the proc in the context of the instance
43
- # for syntactic sugar :)
44
- def draw(&proc)
45
- self.instance_eval(&proc)
46
- end
43
+ # evaluate the proc in the context of the instance
44
+ # for syntactic sugar :)
45
+ def draw(&proc)
46
+ self.instance_eval(&proc)
47
+ end
47
48
 
48
- # make each of these methods that
49
- # when called add route
50
- [:get, :post, :put, :delete].each do |http_method|
51
- define_method(http_method) do |path, controller, action_name|
52
- add_route(path, http_method, controller, action_name)
49
+ # make each of these methods that
50
+ # when called add route
51
+ [:get, :post, :put, :delete].each do |http_method|
52
+ define_method(http_method) do |path, controller, action_name|
53
+ add_route(path, http_method, controller, action_name)
54
+ end
53
55
  end
54
- end
55
56
 
56
- # should return the route that matches this request
57
- def match(req)
58
- @routes.each do |route|
59
- return route if route.matches?(req)
57
+ # should return the route that matches this request
58
+ def match(req)
59
+ @routes.each do |route|
60
+ return route if route.matches?(req)
61
+ end
62
+ nil
60
63
  end
61
- nil
62
- end
63
64
 
64
- # either throw 404 or call run on a matched route
65
- def run(req, res)
66
- route = match(req)
67
- if route
68
- route.run(req, res)
69
- else
70
- res.write("Route #{req.path} could not be found.")
71
- res.status = 404
65
+ # either throw 404 or call run on a matched route
66
+ def run(req, res)
67
+ route = match(req)
68
+ if route
69
+ route.run(req, res)
70
+ else
71
+ res.write("Route #{req.path} could not be found.")
72
+ res.status = 404
73
+ end
72
74
  end
73
75
  end
74
76
  end
data/lib/db/server.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rack'
2
- require_relative './config/routes'
3
- require_relative 'lib/static_viewer'
4
- require_relative 'lib/show_exceptions'
2
+ require './config/routes'
3
+ require_relative 'static_viewer'
4
+ require_relative 'show_exceptions'
5
5
 
6
6
  module TGauge
7
7
  class Server
@@ -23,5 +23,6 @@ module TGauge
23
23
  app: full_app,
24
24
  Port: 3000
25
25
  })
26
+ end
26
27
  end
27
28
  end
@@ -1,5 +1,4 @@
1
1
  require 'erb'
2
- require 'byebug'
3
2
 
4
3
  class ShowExceptions
5
4
  attr_reader :app
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TGauge
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tgauge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nam Kim