nephos-server 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 +4 -4
- data/lib/nephos-server/routing/controller.rb +2 -0
- data/lib/nephos-server/routing/execute.rb +7 -4
- data/lib/nephos-server/routing/load.rb +32 -8
- data/lib/nephos-server/server/basic_errors.rb +1 -0
- data/lib/nephos-server/server/main.rb +6 -1
- data/lib/nephos-server/server/responder.rb +2 -0
- data/nephos-server.gemspec +1 -0
- data/version +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c470980b6da991d95c060efa740e0a89cc82eb30
|
4
|
+
data.tar.gz: d7236c0810fd2c019e5d1a180b63270d950e0a06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d1b932659d821538bc1dd5d706cd9581fb19e6ccc9ab688d96cd745e9be9d2c80b6c6cb39c6bd34209b74d817d93d10f2fabeac6c1cfe7cdd10e68541e3a6a
|
7
|
+
data.tar.gz: a267ce338cc75df3ca25e91e71dd29473bb952dccb6244ed99ccaf5dfccd35d80bcb2c15a492225506192d16e336890b0dfad48882e4b2093e808b45d8169fb8
|
@@ -10,13 +10,17 @@ module Nephos
|
|
10
10
|
|
11
11
|
ALL = []
|
12
12
|
|
13
|
+
# @params: arg [Hash or Symbol]
|
14
|
+
# shortcut to #{Nephos::Responder.render}
|
13
15
|
def self.render arg
|
14
16
|
Responder.render arg
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
# @params: path [Array]
|
20
|
+
# find the right route to use from the url
|
21
|
+
def self.parse_path path, verb
|
18
22
|
route = "/" + path.join("/")
|
19
|
-
return ALL.find{|e| e[:url] == route}
|
23
|
+
return ALL.find{|e| e[:url] == route and e[:verb] == verb}
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.execute(env)
|
@@ -27,9 +31,8 @@ module Nephos
|
|
27
31
|
args = Hash[route.query.to_s.split("&").map{|e| e.split("=")}]
|
28
32
|
puts "#{from} [#{verb}] \t ---> \t #{route}"
|
29
33
|
parsed = {route: route, verb: verb, from: from, path: path, args: args}
|
30
|
-
call = parse_path(path)
|
34
|
+
call = parse_path(path, verb)
|
31
35
|
return render status: 404 if call.nil?
|
32
|
-
call = parse_path(path)
|
33
36
|
begin
|
34
37
|
controller = Module.const_get(call[:controller]).new(env, parsed)
|
35
38
|
return render(controller.send(call[:method]) || {status: 500})
|
@@ -2,17 +2,41 @@ class RoutingError < Exception; end
|
|
2
2
|
class InvalidRoute < RoutingError; end
|
3
3
|
class InvalidGetRoute < InvalidRoute; end
|
4
4
|
|
5
|
-
|
5
|
+
module Nephos
|
6
|
+
module Route
|
7
|
+
|
8
|
+
def self.add(what, verb)
|
9
|
+
Nephos::Route::ALL << what.merge(verb: verb)
|
10
|
+
puts "[#{verb}] #{what[:url]} \t ---> \t #{what[:controller]}##{what[:method]}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.check!(what)
|
14
|
+
raise InvalidGetRoute if not what.keys.include? :url
|
15
|
+
raise InvalidGetRoute if not what.keys.include? :controller
|
16
|
+
raise InvalidGetRoute if not what.keys.include? :method
|
17
|
+
# TODO: more check to do
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @params: what [Hash]
|
6
24
|
def get what
|
7
|
-
|
8
|
-
|
9
|
-
|
25
|
+
Nephos::Route.check!(what)
|
26
|
+
Nephos::Route.add(what, "GET")
|
27
|
+
end
|
10
28
|
|
11
|
-
|
29
|
+
# @params: what [Hash]
|
30
|
+
def post what
|
31
|
+
Nephos::Route.check!(what)
|
32
|
+
Nephos::Route.add(what, "POST")
|
33
|
+
end
|
12
34
|
|
13
|
-
|
14
|
-
|
35
|
+
# @params: what [Hash]
|
36
|
+
def put what
|
37
|
+
Nephos::Route.check!(what)
|
38
|
+
Nephos::Route.add(what, "PUT")
|
15
39
|
end
|
16
40
|
|
17
|
-
# require_relative '../../../routes.rb'
|
18
41
|
load 'routes.rb'
|
42
|
+
puts
|
@@ -0,0 +1 @@
|
|
1
|
+
class InvalidApplicationError < RuntimeError ; end
|
@@ -7,14 +7,19 @@ module Nephos
|
|
7
7
|
|
8
8
|
SERVER = lambda {|env| return Route.execute(env)}
|
9
9
|
|
10
|
+
attr_accessor :port
|
11
|
+
|
12
|
+
# @params: port [Integer] port to listen
|
10
13
|
def initialize port
|
11
|
-
@port = port
|
14
|
+
@port = Integer(port)
|
12
15
|
end
|
13
16
|
|
17
|
+
# start the Rack server
|
14
18
|
def start
|
15
19
|
Rack::Server.start :app => SERVER, :Port => @port
|
16
20
|
end
|
17
21
|
|
22
|
+
# start the Rack server on a instance of Nephos::Server
|
18
23
|
def self.start port
|
19
24
|
Server.new(port).start
|
20
25
|
end
|
@@ -5,6 +5,8 @@ module Nephos
|
|
5
5
|
CT_TP = {'Content-type' => 'text/plain' + CT_CHARSET_}
|
6
6
|
CT_TJ = {'Content-type' => 'text/javascript' + CT_CHARSET_}
|
7
7
|
CT_TH = {'Content-type' => 'text/html' + CT_CHARSET_}
|
8
|
+
|
9
|
+
# @params: params [Hash, Symbol]
|
8
10
|
def self.render params
|
9
11
|
if params == :empty
|
10
12
|
return [204, CT_TP, [""]]
|
data/nephos-server.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
'lib/nephos-server.rb',
|
13
13
|
'lib/nephos-server/server/main.rb',
|
14
14
|
'lib/nephos-server/server/responder.rb',
|
15
|
+
'lib/nephos-server/server/basic_errors.rb',
|
15
16
|
'lib/nephos-server/routing/execute.rb',
|
16
17
|
'lib/nephos-server/routing/load.rb',
|
17
18
|
'lib/nephos-server/routing/controller.rb',
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nephos-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
@@ -45,6 +45,7 @@ email:
|
|
45
45
|
- - lib/nephos-server.rb
|
46
46
|
- lib/nephos-server/server/main.rb
|
47
47
|
- lib/nephos-server/server/responder.rb
|
48
|
+
- lib/nephos-server/server/basic_errors.rb
|
48
49
|
- lib/nephos-server/routing/execute.rb
|
49
50
|
- lib/nephos-server/routing/load.rb
|
50
51
|
- lib/nephos-server/routing/controller.rb
|
@@ -76,6 +77,7 @@ files:
|
|
76
77
|
- lib/nephos-server/routing/controller.rb
|
77
78
|
- lib/nephos-server/routing/execute.rb
|
78
79
|
- lib/nephos-server/routing/load.rb
|
80
|
+
- lib/nephos-server/server/basic_errors.rb
|
79
81
|
- lib/nephos-server/server/main.rb
|
80
82
|
- lib/nephos-server/server/responder.rb
|
81
83
|
- nephos-server.gemspec
|