nephos-server 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/DOCUMENTATION/GUIDE_ROUTER.md +5 -1
- data/README.md +7 -0
- data/app/main.rb +2 -2
- data/bin/nephos-generator +1 -1
- data/lib/nephos-server/controller.rb +18 -10
- data/lib/nephos-server/router/load.rb +2 -1
- data/test/router.rb +32 -6
- data/version +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837711f9cdfb6dbb77a5c9c5a0964bd3f603c0c5
|
4
|
+
data.tar.gz: 1d69471c358c7a4e042dcabbbeb6d2002f55c1ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 807f30fb29bdc799e41180f9af31357aaae7c62118a551ff0e674419e6a6431b994e2a02c241a2e187d102dc3e5fea4349408c95fda63431f81f13dc62f0f4a9
|
7
|
+
data.tar.gz: 69442d3daba27976f008181bfaa7bff0746d0278267e24749962fae8320ee1961ed0a3ac5ec610021b8416e50ae45db67a7213a37551d4160a8243589f25b22a
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v0.6.2
|
2
|
+
* Fix generator (bug when --application on current directory)
|
3
|
+
* Improve hooks (add the :only option)
|
4
|
+
* Improve documentation
|
5
|
+
* Improve routing (more tests, better duplicate / handlement)
|
6
|
+
|
1
7
|
v0.6.1
|
2
8
|
* Improve daemons
|
3
9
|
* Improve Rakefile and tests structure
|
@@ -62,6 +62,10 @@ It will generate the route ``/home/index``, calling the ``MainController#root``
|
|
62
62
|
|
63
63
|
## URL Parameters
|
64
64
|
|
65
|
-
**TODO**
|
65
|
+
**TODO: more documentation**
|
66
66
|
|
67
67
|
place a ``/:param`` in your route. The parameter will be placed in the controller in the ``params`` method
|
68
|
+
|
69
|
+
## Notes
|
70
|
+
|
71
|
+
* When a request is done, duplicate / are not counted. So, ``/resource/id`` is equivalent to ``////resource//id`` etc.
|
data/README.md
CHANGED
@@ -128,10 +128,17 @@ end
|
|
128
128
|
- Database creation
|
129
129
|
- Web HTML with templating
|
130
130
|
|
131
|
+
Gitlab Continuous Integration:
|
131
132
|
[![Gitlab Tests](https://gitlab.com/ci/projects/8973/status.png?ref=master)](https://gitlab.com/ci/projects/8973?ref=master)
|
132
133
|
|
134
|
+
Github version
|
133
135
|
[![GitHub version](https://badge.fury.io/gh/pouleta%2FNephosRubyServer.svg)](http://badge.fury.io/gh/pouleta%2FNephosRubyServer)
|
134
136
|
|
137
|
+
Released version on ruby-gems
|
138
|
+
[![Gem Version](https://badge.fury.io/rb/nephos-server.svg)](http://badge.fury.io/rb/nephos-server)
|
139
|
+
|
140
|
+
Code Quality
|
135
141
|
[![Code Climate](https://codeclimate.com/github/pouleta/NephosRubyServer/badges/gpa.svg)](https://codeclimate.com/github/pouleta/NephosRubyServer)
|
136
142
|
|
143
|
+
Nephos gem version
|
137
144
|
[![Nephos Executables](https://badge.fury.io/rb/nephos.svg)](http://badge.fury.io/rb/nephos)
|
data/app/main.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class MainController < Nephos::Controller
|
2
2
|
|
3
3
|
before_action :fct_before_all
|
4
|
-
before_action :fct_before_root, :root
|
5
|
-
after_action :fct_after_root, :root
|
4
|
+
before_action :fct_before_root, only: [:root]
|
5
|
+
after_action :fct_after_root, only: :root
|
6
6
|
|
7
7
|
def fct_before_all
|
8
8
|
# puts "BEFORE ALL"
|
data/bin/nephos-generator
CHANGED
@@ -105,7 +105,7 @@ EOF
|
|
105
105
|
|
106
106
|
module Application
|
107
107
|
def self.create_application_dir dir
|
108
|
-
raise BinError, "Directory #{dir} already exists" if Dir.exists? dir
|
108
|
+
raise BinError, "Directory #{dir} already exists" if Dir.exists? dir and dir != "."
|
109
109
|
Dir.mkdir dir
|
110
110
|
end
|
111
111
|
|
@@ -32,14 +32,17 @@ module Nephos
|
|
32
32
|
|
33
33
|
def self.parse_action_opts(opt)
|
34
34
|
if opt.nil?
|
35
|
-
return :'*'
|
35
|
+
if block_given? then yield :'*' else return [:'*'] end
|
36
36
|
elsif opt.is_a? Hash
|
37
|
-
|
37
|
+
only = Array(opt[:only])
|
38
|
+
if block_given? then only.each{|e| yield e} else return only end
|
39
|
+
except = opt[:except]
|
40
|
+
raise "No implemented yet (except)" if except
|
38
41
|
# parse :only and :except
|
39
42
|
elsif opt.is_a? String or opt.is_a? Symbol
|
40
|
-
return opt
|
43
|
+
if block_given? then yield opt else return [opt] end
|
41
44
|
else
|
42
|
-
raise ArgumentError, "Invalid
|
45
|
+
raise ArgumentError, "Invalid opt"
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
@@ -49,18 +52,22 @@ module Nephos
|
|
49
52
|
# - if Hash, it will be parsed with rules :only and :except
|
50
53
|
# - if String or Symbol, it will be parsed as :only
|
51
54
|
def self.before_action(method, opt=nil)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
parse_action_opts(opt) do |call|
|
56
|
+
@@before_action[call] ||= []
|
57
|
+
@@before_action[call] << method.to_sym
|
58
|
+
end
|
55
59
|
end
|
56
60
|
|
57
61
|
# see {#self.before_action}
|
58
62
|
def self.after_action(method, opt=nil)
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
parse_action_opts(opt) do |call|
|
64
|
+
@@after_action[call] ||= []
|
65
|
+
@@after_action[call] << method.to_sym
|
66
|
+
end
|
62
67
|
end
|
63
68
|
|
69
|
+
# It calls every registred hooks added to the @before_action list,
|
70
|
+
# including '*'
|
64
71
|
def execute_before_action(call)
|
65
72
|
call = call.to_sym
|
66
73
|
methods = []
|
@@ -71,6 +78,7 @@ module Nephos
|
|
71
78
|
end
|
72
79
|
end
|
73
80
|
|
81
|
+
# see {#self.execute_before_action}
|
74
82
|
def execute_after_action(call)
|
75
83
|
call = call.to_sym
|
76
84
|
methods = []
|
@@ -14,9 +14,10 @@ module Nephos
|
|
14
14
|
params = what[:url].split('/').map do |p|
|
15
15
|
p.match(/:\w+/) ? {p: "[^\/]+", name: p} : {p: p, name: nil}
|
16
16
|
end
|
17
|
-
url = params.map{|e| e[:p]}.join("
|
17
|
+
url = params.map{|e| e[:p]}.join("/+")
|
18
18
|
url = "/" if url.empty?
|
19
19
|
what[:match] = /^#{url}\/*$/
|
20
|
+
# remove : in :param, and / in /param
|
20
21
|
what[:params] = params.map{|e| e[:name] && e[:name][1..-1]}[1..-1] || []
|
21
22
|
end
|
22
23
|
|
data/test/router.rb
CHANGED
@@ -59,7 +59,9 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
59
59
|
assert_equal "GET", first[:verb]
|
60
60
|
assert_equal "TestController", first[:controller]
|
61
61
|
assert_equal "method", first[:method]
|
62
|
-
|
62
|
+
assert "/".match(first[:match])
|
63
|
+
assert "//".match(first[:match])
|
64
|
+
assert "///".match(first[:match])
|
63
65
|
|
64
66
|
reset_routes!
|
65
67
|
post url: "/", controller: "TestController", method: "method", silent: true
|
@@ -67,7 +69,9 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
67
69
|
assert_equal "POST", first[:verb]
|
68
70
|
assert_equal "TestController", first[:controller]
|
69
71
|
assert_equal "method", first[:method]
|
70
|
-
|
72
|
+
assert "/".match(first[:match])
|
73
|
+
assert "//".match(first[:match])
|
74
|
+
assert "///".match(first[:match])
|
71
75
|
|
72
76
|
reset_routes!
|
73
77
|
put url: "/", controller: "TestController", method: "method", silent: true
|
@@ -75,14 +79,21 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
75
79
|
assert_equal "PUT", first[:verb]
|
76
80
|
assert_equal "TestController", first[:controller]
|
77
81
|
assert_equal "method", first[:method]
|
78
|
-
|
82
|
+
assert "/".match(first[:match])
|
83
|
+
assert "//".match(first[:match])
|
84
|
+
assert "///".match(first[:match])
|
79
85
|
end
|
80
86
|
|
81
87
|
def test_valid_routes_params
|
82
88
|
reset_routes!
|
83
89
|
get url: "/:what", controller: "TestController", method: "method", silent: true
|
84
90
|
assert_equal "/:what", first[:url]
|
85
|
-
|
91
|
+
assert !"/".match(first[:match])
|
92
|
+
assert !"//".match(first[:match])
|
93
|
+
assert !"///".match(first[:match])
|
94
|
+
assert "/data".match(first[:match])
|
95
|
+
assert "/111".match(first[:match])
|
96
|
+
assert "/--_--".match(first[:match])
|
86
97
|
end
|
87
98
|
|
88
99
|
def test_valid_resources
|
@@ -102,7 +113,11 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
102
113
|
get url: "/:what", controller: "TestController", method: "method", silent: true
|
103
114
|
end
|
104
115
|
assert_equal "/home/:what", first[:url]
|
105
|
-
|
116
|
+
assert !"/JOME/data".match(first[:match])
|
117
|
+
assert !"/1".match(first[:match])
|
118
|
+
assert !"/home".match(first[:match])
|
119
|
+
assert "/home/data".match(first[:match])
|
120
|
+
assert "/home/1".match(first[:match])
|
106
121
|
end
|
107
122
|
|
108
123
|
def test_valid_resources_params2
|
@@ -111,9 +126,19 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
111
126
|
get url: "/show", controller: "TestController", method: "method", silent: true
|
112
127
|
end
|
113
128
|
assert_equal "/:id/show", first[:url]
|
114
|
-
|
129
|
+
assert !"/".match(first[:match])
|
130
|
+
assert !"/x".match(first[:match])
|
131
|
+
assert !"/xx".match(first[:match])
|
132
|
+
assert !"//1".match(first[:match])
|
133
|
+
assert !"/x/1".match(first[:match])
|
134
|
+
assert !"/1/x".match(first[:match])
|
135
|
+
assert !"/x//1".match(first[:match])
|
136
|
+
assert "/1/show".match(first[:match])
|
137
|
+
assert "/show/show".match(first[:match])
|
138
|
+
assert "/1//show".match(first[:match])
|
115
139
|
end
|
116
140
|
|
141
|
+
REQ_GET_INDEX_ROOTx2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"//index"})
|
117
142
|
REQ_GET_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index"})
|
118
143
|
REQ_POST_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index"})
|
119
144
|
REQ_PUT_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"PUT", "PATH_INFO"=>"/index"})
|
@@ -124,6 +149,7 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
124
149
|
reset_routes!
|
125
150
|
get url: "/index", controller: "TestController", method: "method", silent: true
|
126
151
|
post url: "/index", controller: "TestController", method: "method", silent: true
|
152
|
+
assert(Nephos::Router.new.find_route(REQ_GET_INDEX_ROOTx2))
|
127
153
|
assert(Nephos::Router.new.find_route(REQ_GET_INDEX))
|
128
154
|
assert(Nephos::Router.new.find_route(REQ_POST_INDEX))
|
129
155
|
assert(!Nephos::Router.new.find_route(REQ_PUT_INDEX))
|
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nephos-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nomorebeer
|