nephos-server 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/nephos-server.rb +2 -0
- data/lib/nephos-server/basic_errors.rb +3 -0
- data/lib/nephos-server/controller.rb +29 -0
- data/lib/nephos-server/params.rb +25 -0
- data/lib/nephos-server/routing/execute.rb +0 -2
- data/lib/nephos-server/routing/load.rb +2 -2
- data/nephos-server.gemspec +4 -1
- data/test/controller.rb +9 -0
- data/test/params.rb +14 -0
- data/test/responder.rb +0 -1
- data/test/test.rb +2 -0
- data/version +1 -1
- metadata +9 -3
- data/lib/nephos-server/routing/controller.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8b7fa251ffb5faae0d07c460068da7b1462c69f
|
4
|
+
data.tar.gz: 7ef60b41475e3763ac0b9cfc6c177d0556099ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7e88e906675e7f39d5f736cf554719caaaf97eb5f6269b098b6371ac7f0fcdb3d7f9d8e7473325e8d412aa980b9c229e5dc3412c3ff9b5fe1f150274083020
|
7
|
+
data.tar.gz: e7002eca788be88b22dd135506afad8cc14b76775c33e323ea170c1d33c0d6305a9f5de1a0731afeb82ae7393afb3bc333073bebf421d7666b887ab1f510001e
|
data/README.md
CHANGED
@@ -41,7 +41,11 @@ The basic code of a controller can be generated via ``nephos-generator controlle
|
|
41
41
|
```ruby
|
42
42
|
class Example < Nephos::Controller
|
43
43
|
def root
|
44
|
-
|
44
|
+
if params["index"] == "true"
|
45
|
+
return {plain: "index"}
|
46
|
+
else
|
47
|
+
return :empty
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
47
51
|
```
|
data/lib/nephos-server.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Nephos
|
2
|
+
class Controller
|
3
|
+
|
4
|
+
attr_reader :env, :infos, :callpath
|
5
|
+
|
6
|
+
# @param env [Hash] env extracted from the http request
|
7
|
+
# @param parsed [Hash] pre-parsed env with parameters, ...
|
8
|
+
def initialize env={}, parsed={path: [], args: {}}, callpath={params: []}
|
9
|
+
raise ArgumentError, "env must be a Hash" unless env.is_a? Hash
|
10
|
+
raise ArgumentError, "parsed must be a Hash" unless parsed.is_a? Hash
|
11
|
+
raise ArgumentError, "callpath must be a Hash" unless callpath.is_a? Hash
|
12
|
+
raise ArgumentError, "Invalid Parsed. :path must be associated with an Array" unless parsed[:path].is_a? Array
|
13
|
+
raise ArgumentError, "Invalid Parsed. :args must be associated with a Hash" unless parsed[:args].is_a? Hash
|
14
|
+
raise ArgumentError, "Invalid Callpath. :params must be associated with an Array" unless callpath[:params].is_a? Array
|
15
|
+
@env= env
|
16
|
+
@infos= parsed
|
17
|
+
@callpath= callpath
|
18
|
+
@params= parsed[:args]
|
19
|
+
@params.merge! Params.new(Hash[callpath[:params].zip @infos[:path]])
|
20
|
+
@params.select!{|k,v|k}
|
21
|
+
end
|
22
|
+
|
23
|
+
def arguments
|
24
|
+
@params
|
25
|
+
end
|
26
|
+
alias :params :arguments
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Nephos
|
4
|
+
class Params
|
5
|
+
|
6
|
+
def initialize(hash={})
|
7
|
+
raise ArgumentError, "the first argument must be a Hash" unless hash.is_a? Hash
|
8
|
+
@hash = Hash[hash.map{|k,v| [k.to_s, v]}]
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing m, *a
|
12
|
+
@hash.send(m, *(a.map(&:to_s)))
|
13
|
+
@hash.send(m, *a)
|
14
|
+
end
|
15
|
+
|
16
|
+
def [] i
|
17
|
+
@hash[i.to_s]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []= i, v
|
21
|
+
@hash[i.to_s] = v.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -27,7 +27,7 @@ module Nephos
|
|
27
27
|
def self.check_controller! what
|
28
28
|
begin
|
29
29
|
controller = Module.const_get(what[:controller])
|
30
|
-
rescue
|
30
|
+
rescue => err
|
31
31
|
raise InvalidRouteController, "Controller \"#{what[:controller]}\" doesn't exists"
|
32
32
|
end
|
33
33
|
if not controller.ancestors.include? Nephos::Controller
|
@@ -35,7 +35,7 @@ module Nephos
|
|
35
35
|
end
|
36
36
|
begin
|
37
37
|
instance = controller.new
|
38
|
-
rescue
|
38
|
+
rescue => err
|
39
39
|
raise InvalidRouteController, "Cannot initialize controller"
|
40
40
|
end
|
41
41
|
return instance
|
data/nephos-server.gemspec
CHANGED
@@ -11,11 +11,12 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = %w(
|
12
12
|
lib/nephos-server.rb
|
13
13
|
lib/nephos-server/basic_errors.rb
|
14
|
+
lib/nephos-server/params.rb
|
15
|
+
lib/nephos-server/controller.rb
|
14
16
|
lib/nephos-server/server/main.rb
|
15
17
|
lib/nephos-server/server/responder.rb
|
16
18
|
lib/nephos-server/routing/execute.rb
|
17
19
|
lib/nephos-server/routing/load.rb
|
18
|
-
lib/nephos-server/routing/controller.rb
|
19
20
|
README.md
|
20
21
|
Rakefile
|
21
22
|
Procfile
|
@@ -26,6 +27,8 @@ version
|
|
26
27
|
test/test.rb
|
27
28
|
test/responder.rb
|
28
29
|
test/routing.rb
|
30
|
+
test/params.rb
|
31
|
+
test/controller.rb
|
29
32
|
routes.rb
|
30
33
|
controllers/dataset.rb
|
31
34
|
controllers/image.jpg
|
data/test/controller.rb
ADDED
data/test/params.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class TestNephosServerParams < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_basic
|
4
|
+
p = Nephos::Params.new
|
5
|
+
assert p.empty?
|
6
|
+
p[:a] = "1"
|
7
|
+
assert_equal p[:a], "1"
|
8
|
+
assert_equal p["a"], "1"
|
9
|
+
p["a"] = "2"
|
10
|
+
assert_equal p[:a], "2"
|
11
|
+
assert_equal p["a"], "2"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/test/responder.rb
CHANGED
data/test/test.rb
CHANGED
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
@@ -58,11 +58,12 @@ email:
|
|
58
58
|
- poulet_a@epitech.eu
|
59
59
|
- - lib/nephos-server.rb
|
60
60
|
- lib/nephos-server/basic_errors.rb
|
61
|
+
- lib/nephos-server/params.rb
|
62
|
+
- lib/nephos-server/controller.rb
|
61
63
|
- lib/nephos-server/server/main.rb
|
62
64
|
- lib/nephos-server/server/responder.rb
|
63
65
|
- lib/nephos-server/routing/execute.rb
|
64
66
|
- lib/nephos-server/routing/load.rb
|
65
|
-
- lib/nephos-server/routing/controller.rb
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- Procfile
|
@@ -73,6 +74,8 @@ email:
|
|
73
74
|
- test/test.rb
|
74
75
|
- test/responder.rb
|
75
76
|
- test/routing.rb
|
77
|
+
- test/params.rb
|
78
|
+
- test/controller.rb
|
76
79
|
- routes.rb
|
77
80
|
- controllers/dataset.rb
|
78
81
|
- controllers/image.jpg
|
@@ -97,13 +100,16 @@ files:
|
|
97
100
|
- controllers/main.rb
|
98
101
|
- lib/nephos-server.rb
|
99
102
|
- lib/nephos-server/basic_errors.rb
|
100
|
-
- lib/nephos-server/
|
103
|
+
- lib/nephos-server/controller.rb
|
104
|
+
- lib/nephos-server/params.rb
|
101
105
|
- lib/nephos-server/routing/execute.rb
|
102
106
|
- lib/nephos-server/routing/load.rb
|
103
107
|
- lib/nephos-server/server/main.rb
|
104
108
|
- lib/nephos-server/server/responder.rb
|
105
109
|
- nephos-server.gemspec
|
106
110
|
- routes.rb
|
111
|
+
- test/controller.rb
|
112
|
+
- test/params.rb
|
107
113
|
- test/responder.rb
|
108
114
|
- test/routing.rb
|
109
115
|
- test/test.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Nephos
|
2
|
-
class Controller
|
3
|
-
|
4
|
-
attr_reader :env, :infos, :callpath
|
5
|
-
|
6
|
-
# @param env [Hash] env extracted from the http request
|
7
|
-
# @param parsed [Hash] pre-parsed env with parameters, ...
|
8
|
-
def initialize env={}, parsed={path: [], args: {}}, callpath={params: []}
|
9
|
-
@env= env
|
10
|
-
@infos= parsed
|
11
|
-
@callpath= callpath
|
12
|
-
@params= parsed[:args]
|
13
|
-
@params.merge! Hash[callpath[:params].zip @infos[:path]]
|
14
|
-
@params.select!{|k,v|k}
|
15
|
-
end
|
16
|
-
|
17
|
-
def arguments
|
18
|
-
@params
|
19
|
-
end
|
20
|
-
alias :params :arguments
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|