nephos-server 0.6.5 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG +12 -0
- data/DOCUMENTATION/GUIDE_CONTROLLER.md +13 -1
- data/DOCUMENTATION/TEMPLATING/SLIM.md +7 -1
- data/README.md +3 -3
- data/app/main.rb +5 -0
- data/bin/nephos-status +6 -2
- data/lib/nephos-server/controller.rb +5 -0
- data/lib/nephos-server/router/main.rb +2 -2
- data/lib/nephos-server/server/logger.rb +23 -0
- data/lib/nephos-server/server/main.rb +3 -0
- data/lib/nephos-server/server/responder.rb +2 -0
- data/lib/nephos-server.rb +3 -0
- data/nephos-server.gemspec +3 -0
- data/test/controller.rb +23 -0
- data/test/functional/router.rb +2 -0
- data/test/logger.rb +29 -0
- data/test/router.rb +34 -30
- data/test/test.rb +1 -0
- data/version +1 -1
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f56113d904ac347a19a06e151745a8a86ac3824
|
4
|
+
data.tar.gz: c558a51379e268a046fd2f8c1915d762a7fd61e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ee29b97d3682d7fa4cf571f9112be21fbd73e49f4dc2de3325b1b543a853f2bdde98093608bbd8d17c5b37acaac684322aceb1a9da62dce55c0cc48e0758283
|
7
|
+
data.tar.gz: 294375556d2a690a2813404dd68d38c0d56d25055a6ea45057eaabf69fd8e2033a5d67974182c1c4f1ca1954451a4e7dba9b12c4d960658da2264e3a0fb1dfb8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
v0.6.7
|
2
|
+
* Fix gemspec
|
3
|
+
|
4
|
+
v0.6.6
|
5
|
+
* Improve functional tests (router)
|
6
|
+
* Improve executables (status)
|
7
|
+
* Improve router (disable verbose)
|
8
|
+
* Fix executables (status)
|
9
|
+
* Update "nephos" gem to 1.0.4
|
10
|
+
* Add new feature Controller.url_for
|
11
|
+
* Add new feature log
|
12
|
+
|
1
13
|
v0.6.5
|
2
14
|
* Improve routing helpers (optional url parameter)
|
3
15
|
* Add new functional tests (router)
|
@@ -11,6 +11,7 @@ Example:
|
|
11
11
|
cookies.delete("b") # remove a cookie named "b"
|
12
12
|
```
|
13
13
|
|
14
|
+
|
14
15
|
### Params
|
15
16
|
You can access to the parameters (defined by http or via the URI, based on your
|
16
17
|
routing rules).
|
@@ -28,8 +29,11 @@ This format is accessible via the ``format`` method. (alias for ``extension``)
|
|
28
29
|
It is also provided few helpers ``html?`` ``json?`` ``plain?``
|
29
30
|
|
30
31
|
|
31
|
-
###
|
32
|
+
### Environment
|
33
|
+
From your controllers, you can access to the HTTP request via ``req.env``.
|
34
|
+
You can also generate valid url via ``url_for("/resource")``.
|
32
35
|
|
36
|
+
### Hooks
|
33
37
|
A hook is a method, triggered automatically after an action.
|
34
38
|
|
35
39
|
Actually, NephosServer allows you to create 2 kinds of triggers for your hooks:
|
@@ -89,3 +93,11 @@ class MainController < Nephos::Controller
|
|
89
93
|
|
90
94
|
end
|
91
95
|
```
|
96
|
+
|
97
|
+
### Log
|
98
|
+
You can log errors, particular data, etc, simply by using the helper ```log(...)```
|
99
|
+
|
100
|
+
You can set the fd the of file via
|
101
|
+
```ruby
|
102
|
+
Nephos::Logger.fd = File.open("/tmp/app_#{Time.now}.log", "a")
|
103
|
+
```
|
@@ -12,9 +12,15 @@ gem install slim
|
|
12
12
|
## Usage in Nephos Server
|
13
13
|
|
14
14
|
```ruby
|
15
|
+
require 'slim'
|
16
|
+
|
15
17
|
class UserController < Nephos::Controller
|
18
|
+
|
19
|
+
# /user/:id
|
16
20
|
def show
|
17
|
-
|
21
|
+
user = User.find(params[:id])
|
22
|
+
Slim::Template.new() { File.read('app/views/user/show.slim') }.render(nil, {login: user.login})
|
18
23
|
end
|
24
|
+
|
19
25
|
end
|
20
26
|
```
|
data/README.md
CHANGED
@@ -62,13 +62,13 @@ You should user ``ngenerator --controller NAME`` to generate a new controller.
|
|
62
62
|
|
63
63
|
```ruby
|
64
64
|
class Example < Nephos::Controller
|
65
|
-
def root
|
65
|
+
def root
|
66
66
|
cookies["last_visit"] = Time.now
|
67
67
|
if params["index"] == "true"
|
68
68
|
return {plain: "index"}
|
69
69
|
else
|
70
|
-
|
71
|
-
|
70
|
+
return :empty
|
71
|
+
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
```
|
data/app/main.rb
CHANGED
data/bin/nephos-status
CHANGED
@@ -28,8 +28,10 @@ begin
|
|
28
28
|
not File.read($gfl).split.index("nephos-server")
|
29
29
|
raise "\"#{$dir}\" is not a valid nephos-server application"
|
30
30
|
else
|
31
|
-
|
32
|
-
version =
|
31
|
+
data = File.read($gfl).split("\n").map(&:strip)
|
32
|
+
version = data.map{|e| e.match /nephos-server \((?<version>\d+(\.\d+)+)\)/ }.compact.first
|
33
|
+
raise "\"#{$gfl}\" doesn't contain a valid nephos-server version" unless version
|
34
|
+
version = version["version"]
|
33
35
|
path = $gfl.gsub(/Gemfile\.lock$/, "")
|
34
36
|
n_controllers = 0
|
35
37
|
Dir[File.expand_path 'app/*.rb'].each do |f|
|
@@ -38,6 +40,8 @@ begin
|
|
38
40
|
puts "Full path: #{path}"
|
39
41
|
puts "Installed nephos-version: #{version}"
|
40
42
|
puts "Controllers (#{n_controllers})"
|
43
|
+
daemon = $dir + "/.pid"
|
44
|
+
puts "The application is deploye as daemon (#{File.read(daemon)})" if File.exists? daemon
|
41
45
|
end
|
42
46
|
else
|
43
47
|
raise "\"#{$dir}\" is not a valid directory"
|
@@ -40,6 +40,11 @@ module Nephos
|
|
40
40
|
%w(txt raw).include? extension
|
41
41
|
end
|
42
42
|
|
43
|
+
# @return [String] an url formated as "scheme://host:port/path"
|
44
|
+
def url_for(path="")
|
45
|
+
(URI(req.env["rack.url_scheme"] + "://" + req.env['HTTP_HOST'] + "/") + path).to_s
|
46
|
+
end
|
47
|
+
|
43
48
|
@@before_action = {:'*' => []}
|
44
49
|
@@after_action = {:'*' => []}
|
45
50
|
|
@@ -73,8 +73,8 @@ module Nephos
|
|
73
73
|
begin
|
74
74
|
return render_controller(req, call)
|
75
75
|
rescue => err
|
76
|
-
STDERR.puts "Error: #{err.message}"
|
77
|
-
STDERR.puts err.backtrace
|
76
|
+
STDERR.puts "Error: #{err.message}" unless @silent
|
77
|
+
STDERR.puts err.backtrace unless @silent
|
78
78
|
return error_custom(req, 500, "#{err.message}\n---Backtrace---\n#{err.backtrace.join("\n")}\n")
|
79
79
|
end
|
80
80
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Nephos
|
4
|
+
|
5
|
+
module Logger
|
6
|
+
|
7
|
+
@@fd = STDOUT
|
8
|
+
def self.write(*what)
|
9
|
+
what.flatten.each{|e| @@fd.write("#{e}\n")}
|
10
|
+
@@fd.flush
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.fd= fd
|
14
|
+
@@fd = fd
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.log *what
|
20
|
+
Logger.write what
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/nephos-server.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# require 'yaml'
|
4
4
|
require 'json'
|
5
5
|
require 'open-uri'
|
6
|
+
require 'uri'
|
6
7
|
require 'rack'
|
7
8
|
require 'colorize'
|
8
9
|
|
@@ -13,5 +14,7 @@ require_relative 'nephos-server/basic_errors'
|
|
13
14
|
require_relative 'nephos-server/params'
|
14
15
|
require_relative 'nephos-server/controller'
|
15
16
|
require_relative 'nephos-server/router/main'
|
17
|
+
|
16
18
|
# server
|
19
|
+
require_relative 'nephos-server/server/logger'
|
17
20
|
require_relative 'nephos-server/server/main'
|
data/nephos-server.gemspec
CHANGED
@@ -15,6 +15,7 @@ lib/nephos-server/params.rb
|
|
15
15
|
lib/nephos-server/router/main.rb
|
16
16
|
lib/nephos-server/router/load.rb
|
17
17
|
lib/nephos-server/router/helpers.rb
|
18
|
+
lib/nephos-server/server/logger.rb
|
18
19
|
lib/nephos-server/server/main.rb
|
19
20
|
lib/nephos-server/server/responder.rb
|
20
21
|
lib/nephos-server/version.rb
|
@@ -39,7 +40,9 @@ test/test.rb
|
|
39
40
|
test/responder.rb
|
40
41
|
test/router.rb
|
41
42
|
test/params.rb
|
43
|
+
test/logger.rb
|
42
44
|
test/controller.rb
|
45
|
+
|
43
46
|
test/functional.rb
|
44
47
|
test/functional/generator.rb
|
45
48
|
test/functional/global.rb
|
data/test/controller.rb
CHANGED
@@ -27,4 +27,27 @@ class TestNephosServerController < Test::Unit::TestCase
|
|
27
27
|
assert_equal "v", c.params["k"]
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_url_for
|
31
|
+
r1 = ReqWithWritableParams.new({"REQUEST_METHOD"=>"GET",
|
32
|
+
"PATH_INFO"=>"/",
|
33
|
+
"REQUEST_URI"=>"/",
|
34
|
+
"HTTP_HOST"=>"localhost:8080",
|
35
|
+
"rack.url_scheme"=>"http"})
|
36
|
+
r2 = ReqWithWritableParams.new({"REQUEST_METHOD"=>"GET",
|
37
|
+
"PATH_INFO"=>"/index",
|
38
|
+
"REQUEST_URI"=>"/index?k=v",
|
39
|
+
"HTTP_HOST"=>"localhost:8081",
|
40
|
+
"rack.url_scheme"=>"https"})
|
41
|
+
c1 = Nephos::Controller.new(r1, {params: []})
|
42
|
+
c2 = Nephos::Controller.new(r2, {params: []})
|
43
|
+
assert_equal("http://localhost:8080/", c1.url_for(""))
|
44
|
+
assert_equal("http://localhost:8080/", c1.url_for("/"))
|
45
|
+
assert_equal("http://localhost:8080/sh", c1.url_for("sh"))
|
46
|
+
assert_equal("http://localhost:8080/sh/oh", c1.url_for("sh/oh"))
|
47
|
+
assert_equal("https://localhost:8081/", c2.url_for(""))
|
48
|
+
assert_equal("https://localhost:8081/", c2.url_for("/"))
|
49
|
+
assert_equal("https://localhost:8081/sh", c2.url_for("sh"))
|
50
|
+
assert_equal("https://localhost:8081/sh/oh", c2.url_for("sh/oh"))
|
51
|
+
end
|
52
|
+
|
30
53
|
end
|
data/test/functional/router.rb
CHANGED
data/test/logger.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class TestNephosServerLogger < Test::Unit::TestCase
|
4
|
+
|
5
|
+
FILE = "/tmp/nephos_test_#{Time.now}.log"
|
6
|
+
|
7
|
+
def test_basic
|
8
|
+
fd = File.open(FILE, "w")
|
9
|
+
Nephos::Logger.fd = fd
|
10
|
+
Nephos::Logger.write "coucou"
|
11
|
+
assert_equal("coucou\n", File.read(FILE))
|
12
|
+
File.delete FILE
|
13
|
+
|
14
|
+
fd = File.open(FILE, "w")
|
15
|
+
Nephos::Logger.fd = fd
|
16
|
+
Nephos::Logger.write %w(hello wôrld)
|
17
|
+
assert_equal("hello\nwôrld\n", File.read(FILE))
|
18
|
+
File.delete FILE
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_basic_shortcut
|
22
|
+
fd = File.open(FILE, "w")
|
23
|
+
Nephos::Logger.fd = fd
|
24
|
+
Nephos.log %w(hello wôrld)
|
25
|
+
assert_equal("hello\nwôrld\n", File.read(FILE))
|
26
|
+
File.delete FILE
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/router.rb
CHANGED
@@ -149,12 +149,13 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
149
149
|
reset_routes!
|
150
150
|
get url: "/index", controller: "TestController", method: "method", silent: true
|
151
151
|
post url: "/index", controller: "TestController", method: "method", silent: true
|
152
|
-
|
153
|
-
assert(
|
154
|
-
assert(
|
155
|
-
assert(
|
156
|
-
assert(!
|
157
|
-
assert(!
|
152
|
+
r = Nephos::Router.new(silent: true)
|
153
|
+
assert(r.find_route(REQ_GET_INDEX_ROOTx2))
|
154
|
+
assert(r.find_route(REQ_GET_INDEX))
|
155
|
+
assert(r.find_route(REQ_POST_INDEX))
|
156
|
+
assert(!r.find_route(REQ_PUT_INDEX))
|
157
|
+
assert(!r.find_route(REQ_GET_INDEXX))
|
158
|
+
assert(!r.find_route(REQ_GET_INDE))
|
158
159
|
end
|
159
160
|
|
160
161
|
REQ_GET_ID_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/id/index"})
|
@@ -167,11 +168,12 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
167
168
|
reset_routes!
|
168
169
|
get url: "/:id", controller: "TestController", method: "method1", silent: true
|
169
170
|
get url: "/:id/index", controller: "TestController", method: "method2", silent: true
|
170
|
-
|
171
|
-
assert(
|
172
|
-
assert(
|
173
|
-
assert(
|
174
|
-
assert(
|
171
|
+
r = Nephos::Router.new(silent: true)
|
172
|
+
assert(r.find_route(REQ_GET_ID_INDEX))
|
173
|
+
assert(r.find_route(REQ_GET_XXX_INDEX))
|
174
|
+
assert(r.find_route(REQ_GET_ID))
|
175
|
+
assert(r.find_route(REQ_GET_XXX))
|
176
|
+
assert(!r.find_route(REQ_GET_INDEX_ID))
|
175
177
|
end
|
176
178
|
|
177
179
|
REQ_GET_IDX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/idx/index"})
|
@@ -192,25 +194,27 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
192
194
|
get url: "/index", controller: "TestController", method: "method1", silent: true
|
193
195
|
get url: "/index/:id", controller: "TestController", method: "method1", silent: true
|
194
196
|
post url: "/index/:id/index", controller: "TestController", method: "method2", silent: true
|
197
|
+
r = Nephos::Router.new(silent: true)
|
195
198
|
|
196
|
-
assert(!
|
197
|
-
assert(!
|
198
|
-
assert(!
|
199
|
-
assert(!
|
199
|
+
assert(!r.find_route(REQ_GET_IDX_INDEX))
|
200
|
+
assert(!r.find_route(REQ_GET_XXX_INDEX))
|
201
|
+
assert(!r.find_route(REQ_GET_ID))
|
202
|
+
assert(!r.find_route(REQ_GET_XXX))
|
200
203
|
|
201
|
-
assert(
|
202
|
-
assert(
|
203
|
-
assert(
|
204
|
+
assert(r.find_route(REQ_GET_INDEX_ID))
|
205
|
+
assert(r.find_route(REQ_GET_INDEX_XXX))
|
206
|
+
assert(r.find_route(REQ_POST_INDEX_XXX_INDEX))
|
204
207
|
|
205
|
-
assert(!
|
206
|
-
assert(!
|
207
|
-
assert(!
|
208
|
+
assert(!r.find_route(REQ_GET_INDEX_XXX_INDEX))
|
209
|
+
assert(!r.find_route(REQ_POST_INDEX_XXX_ID))
|
210
|
+
assert(!r.find_route(REQ_POST_INDEX_XXX_XXX))
|
208
211
|
end
|
209
212
|
|
210
213
|
def test_routing_extension
|
211
214
|
reset_routes!
|
212
215
|
get url: "/index", controller: "TestController", method: "method1", silent: true
|
213
216
|
get url: "/indexno", controller: "TestController", method: "method1", silent: true, postfix: false
|
217
|
+
r = Nephos::Router.new(silent: true)
|
214
218
|
ok1 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index"})
|
215
219
|
ok2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index.html"})
|
216
220
|
ok3 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index.json"})
|
@@ -220,15 +224,15 @@ class TestNephosServerRouter < Test::Unit::TestCase
|
|
220
224
|
ko2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.html"})
|
221
225
|
ko3 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.json"})
|
222
226
|
ko4 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.xhr"})
|
223
|
-
assert(
|
224
|
-
assert(
|
225
|
-
assert(
|
226
|
-
assert(
|
227
|
-
assert(
|
228
|
-
assert(!
|
229
|
-
assert(!
|
230
|
-
assert(!
|
231
|
-
assert(!
|
227
|
+
assert(r.find_route(ok1))
|
228
|
+
assert(r.find_route(ok2))
|
229
|
+
assert(r.find_route(ok3))
|
230
|
+
assert(r.find_route(ok4))
|
231
|
+
assert(r.find_route(ok5))
|
232
|
+
assert(!r.find_route(ko1))
|
233
|
+
assert(!r.find_route(ko2))
|
234
|
+
assert(!r.find_route(ko3))
|
235
|
+
assert(!r.find_route(ko4))
|
232
236
|
end
|
233
237
|
|
234
238
|
def test_routing_eze_router
|
data/test/test.rb
CHANGED
data/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.7
|
data.tar.gz.sig
CHANGED
Binary file
|
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.6.
|
4
|
+
version: 0.6.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- poulet_a
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
tcYkgfqUJPitIJx1RvWZpIyH5uJhRUYK3+vU9nMOxez5WbIlC1TtpByKAPMX+sht
|
32
32
|
gib3AoIT8jh/2w==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-10-
|
34
|
+
date: 2015-10-23 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nomorebeer
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/nephos-server/router/helpers.rb
|
127
127
|
- lib/nephos-server/router/load.rb
|
128
128
|
- lib/nephos-server/router/main.rb
|
129
|
+
- lib/nephos-server/server/logger.rb
|
129
130
|
- lib/nephos-server/server/main.rb
|
130
131
|
- lib/nephos-server/server/responder.rb
|
131
132
|
- lib/nephos-server/version.rb
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- test/functional/global.rb
|
138
139
|
- test/functional/router.rb
|
139
140
|
- test/functional/server.rb
|
141
|
+
- test/logger.rb
|
140
142
|
- test/params.rb
|
141
143
|
- test/responder.rb
|
142
144
|
- test/router.rb
|
@@ -165,8 +167,6 @@ rubyforge_project:
|
|
165
167
|
rubygems_version: 2.4.8
|
166
168
|
signing_key:
|
167
169
|
specification_version: 4
|
168
|
-
summary: "*
|
169
|
-
tests (router) * Add extension for url (.html, ...) * Add improved router helper
|
170
|
-
(simple destination, alias)"
|
170
|
+
summary: "* Fix gemspec"
|
171
171
|
test_files: []
|
172
172
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|