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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8bb785df5db4f9f8b7a8e4821582700962d0fe4
4
- data.tar.gz: f681de7959a63e202b03f80caf0d730142eaef0d
3
+ metadata.gz: 8f56113d904ac347a19a06e151745a8a86ac3824
4
+ data.tar.gz: c558a51379e268a046fd2f8c1915d762a7fd61e3
5
5
  SHA512:
6
- metadata.gz: ec1e2f6a1d7afe305c39b7664787a31806a60d4f0bc9ed08a1add184f77408b87d09eeb10dbb913662f19ea992a2e3af993584648b0e138f95226c34514f6ac4
7
- data.tar.gz: 41f1943b9e313ee1a45e998565e6628e118ba95fcf434cc591c8f993dd633a15b070b076b0fb2cfed1bcde47d059d56b89a284d8c1923785dc6e04045f4a4432
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
- ### Hooks
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
- #TODO: read a file, use slim with parameters
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
- return :empty
71
- end
70
+ return :empty
71
+ end
72
72
  end
73
73
  end
74
74
  ```
data/app/main.rb CHANGED
@@ -82,6 +82,11 @@ class MainController < Nephos::Controller
82
82
  {}
83
83
  end
84
84
 
85
+ def log_param_x
86
+ Logger.fd = File.open '/tmp/nephos_ftest.log', 'w'
87
+ log "#{params[:x]}"
88
+ end
89
+
85
90
  def err500
86
91
  tessssssssss
87
92
  end
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
- i = File.read($gfl).split.index("nephos-server") + 1
32
- version = File.read($gfl).split[i]
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
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require_relative 'responder'
2
4
 
3
5
  module Nephos
@@ -26,4 +28,5 @@ module Nephos
26
28
  end
27
29
 
28
30
  end
31
+
29
32
  end
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  module Nephos
2
4
 
3
5
  class Responder
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'
@@ -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
@@ -51,6 +51,8 @@ class TestNephosServerAppRouter < Test::Unit::TestCase
51
51
  raise
52
52
  end
53
53
  end
54
+ rep = router.execute(Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/err500"}))
55
+ assert_equal(500, rep.status)
54
56
  end
55
57
 
56
58
  def test_router_on_invalid
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
- assert(Nephos::Router.new.find_route(REQ_GET_INDEX_ROOTx2))
153
- assert(Nephos::Router.new.find_route(REQ_GET_INDEX))
154
- assert(Nephos::Router.new.find_route(REQ_POST_INDEX))
155
- assert(!Nephos::Router.new.find_route(REQ_PUT_INDEX))
156
- assert(!Nephos::Router.new.find_route(REQ_GET_INDEXX))
157
- assert(!Nephos::Router.new.find_route(REQ_GET_INDE))
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
- assert(Nephos::Router.new.find_route(REQ_GET_ID_INDEX))
171
- assert(Nephos::Router.new.find_route(REQ_GET_XXX_INDEX))
172
- assert(Nephos::Router.new.find_route(REQ_GET_ID))
173
- assert(Nephos::Router.new.find_route(REQ_GET_XXX))
174
- assert(!Nephos::Router.new.find_route(REQ_GET_INDEX_ID))
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(!Nephos::Router.new.find_route(REQ_GET_IDX_INDEX))
197
- assert(!Nephos::Router.new.find_route(REQ_GET_XXX_INDEX))
198
- assert(!Nephos::Router.new.find_route(REQ_GET_ID))
199
- assert(!Nephos::Router.new.find_route(REQ_GET_XXX))
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(Nephos::Router.new.find_route(REQ_GET_INDEX_ID))
202
- assert(Nephos::Router.new.find_route(REQ_GET_INDEX_XXX))
203
- assert(Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_INDEX))
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(!Nephos::Router.new.find_route(REQ_GET_INDEX_XXX_INDEX))
206
- assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_ID))
207
- assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_XXX))
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(Nephos::Router.new.find_route(ok1))
224
- assert(Nephos::Router.new.find_route(ok2))
225
- assert(Nephos::Router.new.find_route(ok3))
226
- assert(Nephos::Router.new.find_route(ok4))
227
- assert(Nephos::Router.new.find_route(ok5))
228
- assert(!Nephos::Router.new.find_route(ko1))
229
- assert(!Nephos::Router.new.find_route(ko2))
230
- assert(!Nephos::Router.new.find_route(ko3))
231
- assert(!Nephos::Router.new.find_route(ko4))
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
@@ -6,3 +6,4 @@ require_relative 'responder'
6
6
  require_relative 'router'
7
7
  require_relative 'controller'
8
8
  require_relative 'params'
9
+ require_relative 'logger'
data/version CHANGED
@@ -1 +1 @@
1
- 0.6.5
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.5
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-09 00:00:00.000000000 Z
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: "* Improve routing helpers (optional url parameter) * Add new functional
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