nephos-server 0.6.9 → 0.7.0

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: fe9427a82fb27f38d05a61d389a4908310c1d943
4
- data.tar.gz: 70968b136a8816c7b91fef7c4d5c8b3b4a3c8941
3
+ metadata.gz: 1342d8a4e7a96a441515aa0cd1d051e455004078
4
+ data.tar.gz: 11d0fafb7cc67d032ac12732d1605998f8065440
5
5
  SHA512:
6
- metadata.gz: 0dc889edb2267acd90ca1606b9f999fe70aa7bab5baeec9fd87734d06a307bcd66a0609139695549bdb6189fd51ccab8920201cfe323d4a48dc9b51839c6d7a1
7
- data.tar.gz: 130a86745ed28082f987b755f1a42ba96d03cdf05b00cb1dc1745ffd3608d7e06bf1bcd8a6d177beb1d477635029fc6e07c27f35a41232e1d8c194e5f6c08df0
6
+ metadata.gz: 2efc129fbaa523bf5499a43d4ce1172e7733ab23100590ef8ebca08cbbba979414b65b62ce441bf74e3d2474bca6e6c70b3166cbc84ca60f8fa9d8ea2a6f1bc6
7
+ data.tar.gz: 2e02115d5e1b76a40f36f4509ce42bc28221c76719d5e9ffa9c74e638ead1ebe34129ff51d9668a4aab5f9a7926a25bfd9fb7777bcc89540ba7b6f2e718cb247
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,17 +1,15 @@
1
- v0.6.9
1
+ v0.7.0
2
+ * Remove depreciated method
3
+ * Large cookie improvement (can change the path)
4
+
5
+ v0.6
2
6
  * Fix unitary tests
3
7
  * Fix binary server to handle daemons better
4
8
  * Add unitary test to test the server globaly
5
9
  * Log can be called from the controller
6
-
7
- v0.6.8
8
10
  * Update urls and links
9
11
  * Important fix for cookies
10
-
11
- v0.6.7
12
12
  * Fix gemspec
13
-
14
- v0.6.6
15
13
  * Improve functional tests (router)
16
14
  * Improve executables (status)
17
15
  * Improve router (disable verbose)
@@ -19,34 +17,22 @@ v0.6.6
19
17
  * Update "nephos" gem to 1.0.4
20
18
  * Add new feature Controller.url_for
21
19
  * Add new feature log
22
-
23
- v0.6.5
24
20
  * Improve routing helpers (optional url parameter)
25
21
  * Add new functional tests (router)
26
22
  * Add extension for url (.html, ...)
27
23
  * Add improved router helper (simple destination, alias)
28
-
29
- v0.6.4
30
24
  * Fix application generator (replace in the gemfile nephos-server by nephos)
31
25
  * Improve guides (more doc, corrections, update)
32
26
  * Certificate for sign the gem
33
-
34
- v0.6.3
35
27
  * Add customisable default error page
36
-
37
- v0.6.2
38
28
  * Fix generator (bug when --application on current directory)
39
29
  * Improve hooks (add the :only option)
40
30
  * Improve documentation
41
31
  * Improve routing (more tests, better duplicate / handlement)
42
-
43
- v0.6.1
44
32
  * Improve daemons
45
33
  * Improve Rakefile and tests structure
46
34
  * Add few functional (router, server, generator) tests
47
35
  * Add new unitary tests
48
-
49
- v0.6.0
50
36
  * Big change (ea49dfb0b429f03327447477bfee9bef30dda7ad) on the architecture, massive usage of Rack::Request, review the global architecture, update all unitary tests
51
37
  * add hook before_action and after_action
52
38
  * improve params
@@ -8,12 +8,12 @@ It handles connection with DB, sql request creation, caching, etc.
8
8
  [Sequel documentation](http://sequel.jeremyevans.net/documentation.html)
9
9
 
10
10
  ## Installation
11
-
12
11
  ```bash
13
12
  gem install sequel
14
13
  ```
15
14
 
16
15
  ## Usage
16
+ You can add the following code in ``/sequel.rb``:
17
17
 
18
18
  ```ruby
19
19
  require 'sequel'
@@ -9,8 +9,12 @@ Example:
9
9
  ```ruby
10
10
  cookies["a"] = "b" # add a cookie named "a"
11
11
  cookies.delete("b") # remove a cookie named "b"
12
+ cookies.set_path("a", "/a")
12
13
  ```
13
14
 
15
+ * TODO: Change expiration date, domain, ...
16
+ * Note: By default, every cookie's path is "/"
17
+
14
18
 
15
19
  ### Params
16
20
  You can access to the parameters (defined by http or via the URI, based on your
@@ -4,13 +4,20 @@ Slim is a HTML templating langage, simple to implement in the Nephos Server.
4
4
  [Slim documentation](http://slim-lang.com)
5
5
 
6
6
  ## Installation
7
-
8
7
  ```bash
9
8
  gem install slim
10
9
  ```
11
10
 
12
11
  ## Usage in Nephos Server
12
+ You can add the following code in ``/slim.rb``:
13
+
14
+ ```ruby
15
+ def slim(file, locals)
16
+ Slim::Template.new() { File.read('app/views/' + file) }.render(nil, locals)
17
+ end
18
+ ```
13
19
 
20
+ ### Example
14
21
  ```ruby
15
22
  require 'slim'
16
23
 
@@ -60,7 +60,7 @@ class MainController < Nephos::Controller
60
60
  file = File.expand_path(params["image"], dir)
61
61
  if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
62
62
  return {status: 500, content: "invalid path #{params['image']}"}
63
- elsif not File.exists? file
63
+ elsif not File.exist? file
64
64
  return {status: 404, content: "invalid path #{params['image']}"}
65
65
  else
66
66
  return {type: 'image/jpeg', content: File.read(file)}
@@ -76,9 +76,9 @@ class MainController < Nephos::Controller
76
76
  {json: cookies.to_h}
77
77
  end
78
78
 
79
- # require 'pry'
80
79
  def debug
81
- # binding.pry
80
+ #require 'pry'
81
+ #binding.pry
82
82
  {}
83
83
  end
84
84
 
@@ -78,14 +78,14 @@ module Nephos
78
78
  file = "app/#{lname}.rb"
79
79
  raise_invalid_appli
80
80
  if $remove
81
- if File.exists?(file) and File.read(file).include? "class #{uname} < Nephos::Controller"
81
+ if File.exist?(file) and File.read(file).include? "class #{uname} < Nephos::Controller"
82
82
  File.delete(file)
83
83
  puts "Success: ".yellow + "\"#{file}\" removed"
84
84
  else
85
85
  raise BinError, "\"#{file}\" is not a valid Controller file."
86
86
  end
87
87
  else
88
- if File.exists? file
88
+ if File.exist? file
89
89
  print "Warning: ".yellow + "The file #{file} already exists. Are you sure to erase it ? (y/N) : "
90
90
  r = STDIN.gets.to_s.chomp
91
91
  raise BinError, "File #{file} already exists" unless r.match(/y(es)?/)
@@ -9,40 +9,46 @@ require_relative '../lib/nephos-server/version'
9
9
  class RoutingError < StandardError; end
10
10
 
11
11
  begin
12
- opts = OptionParser.new do |opts|
13
- opts.banner = "Usage<#{Nephos::VERSION}>: nephos-server <options>"
12
+ opts = OptionParser.new do |opt|
13
+ opt.banner = "Usage<#{Nephos::VERSION}>: nephos-server <options>"
14
14
 
15
15
  $server_port = ENV["SERVER_PORT"] || 8080
16
- opts.on("-p=nb", "--port=nb", "Port to listen") do |port|
16
+ opt.on("-p=nb", "--port=nb", "Port to listen") do |port|
17
17
  $server_port = Integer(port)
18
18
  end
19
19
 
20
20
  $server_host = ENV["SERVER_HOST"] || "0.0.0.0"
21
- opts.on("-h=listen", "--host=listen", "Listen on the network") do |host|
21
+ opt.on("-h=listen", "--host=listen", "Listen on the network") do |host|
22
22
  $server_host = host
23
23
  end
24
24
 
25
25
  $server_env = ENV["ENVIRONMENT"] || "development"
26
- opts.on("-e=env", "--env=env", "Environment") do |env|
26
+ opt.on("-e=env", "--env=env", "Environment") do |env|
27
27
  $server_env = env
28
28
  end
29
29
 
30
- opts.on("--debug", "Enable debugging mode") do
30
+ opt.on("--debug", "Enable debugging mode") do
31
31
  $debug = true
32
32
  end
33
33
 
34
- opts.on("--test", "Enable testing mode (for nephos developpers)") do
34
+ opt.on("--test", "Enable testing mode (for nephos developpers)") do
35
35
  $test = true
36
36
  end
37
37
 
38
- opts.on("-d", "--daemon", "Start in background") do
38
+ opt.on("-d", "--daemon", "Start in background") do
39
39
  $daemon = true
40
40
  end
41
41
 
42
- opts.on("-k", "--kill", "Kill the daemon if started") do
42
+ opt.on("-k", "--kill", "Kill the daemon if started") do
43
43
  $kill_daemon = true
44
44
  end
45
45
 
46
+ opt.on("-r", "--restart", "Restart the daemon if started") do
47
+ $restart_daemon = true
48
+ $kill_daemon = true
49
+ $daemon = true
50
+ end
51
+
46
52
  end.parse!
47
53
 
48
54
  Nephos.env = $server_env
@@ -54,7 +60,7 @@ begin
54
60
  pid = Nephos::Bin::Daemon.get_pid
55
61
  Nephos::Bin::Daemon.kill!
56
62
  puts "Daemon #{pid} stopped"
57
- exit 0
63
+ exit 0 unless $restart_daemon
58
64
  end
59
65
  if $daemon and Nephos::Bin::Daemon.started?
60
66
  raise "Unable to start the server: the daemon #{Nephos::Bin::Daemon.get_pid} already exists"
@@ -67,7 +73,7 @@ begin
67
73
  end
68
74
 
69
75
  if not $test and
70
- (not File.exists? "Gemfile.lock" or
76
+ (not File.exist? "Gemfile.lock" or
71
77
  not File.read("Gemfile.lock").split.index("nephos-server"))
72
78
  raise InvalidApplication
73
79
  end
@@ -24,12 +24,12 @@ $dir = opt[0] || "."
24
24
  begin
25
25
  if Dir.exists? $dir
26
26
  $gfl = File.expand_path "Gemfile.lock", $dir
27
- if not File.exists? $gfl or
27
+ if not File.exist? $gfl or
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
31
  data = File.read($gfl).split("\n").map(&:strip)
32
- version = data.map{|e| e.match /nephos-server \((?<version>\d+(\.\d+)+)\)/ }.compact.first
32
+ version = data.map{|e| e.match(/nephos-server \((?<version>\d+(\.\d+)+)\)/) }.compact.first
33
33
  raise "\"#{$gfl}\" doesn't contain a valid nephos-server version" unless version
34
34
  version = version["version"]
35
35
  path = $gfl.gsub(/Gemfile\.lock$/, "")
@@ -41,7 +41,7 @@ begin
41
41
  puts "Installed nephos-version: #{version}"
42
42
  puts "Controllers (#{n_controllers})"
43
43
  daemon = $dir + "/.pid"
44
- puts "The application is deploye as daemon (#{File.read(daemon)})" if File.exists? daemon
44
+ puts "The application is deploye as daemon (#{File.read(daemon)})" if File.exist? daemon
45
45
  end
46
46
  else
47
47
  raise "\"#{$dir}\" is not a valid directory"
@@ -12,6 +12,7 @@ require_relative 'nephos-server/version'
12
12
  # lib
13
13
  require_relative 'nephos-server/basic_errors'
14
14
  require_relative 'nephos-server/params'
15
+ require_relative 'nephos-server/cookies'
15
16
  require_relative 'nephos-server/controller'
16
17
  require_relative 'nephos-server/router/main'
17
18
 
@@ -14,7 +14,7 @@ module Nephos
14
14
  def self.is_a_valid_application? dir="."
15
15
  return false if not Dir.exists? dir
16
16
  gfl = File.expand_path "Gemfile.lock", dir
17
- return false if not File.exists? gfl
17
+ return false if not File.exist? gfl
18
18
  return false if not File.read(gfl).split.index("nephos-server")
19
19
  return true
20
20
  end
@@ -49,7 +49,7 @@ module Nephos
49
49
  end
50
50
 
51
51
  def self.get_pid
52
- return nil if not File.exists?(get_pid_file)
52
+ return nil if not File.exist?(get_pid_file)
53
53
  v = File.read(get_pid_file)
54
54
  v = Integer(v) rescue nil
55
55
  return v
@@ -25,7 +25,7 @@ module Nephos
25
25
  @params.select!{|k,v| not k.to_s.empty?}
26
26
 
27
27
  @params = Params.new(@params)
28
- @cookies = Params.new(@req.cookies)
28
+ @cookies = Cookies.new(@req.cookies)
29
29
 
30
30
  @extension = extension.to_s.split(".").last
31
31
  end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ module Nephos
4
+
5
+ # Params to a hash, where every elements are accessibles via a stringified key
6
+ # so, even if the entry was added with the key :KEY, it will be accessible via
7
+ # a string equivalent to :key.to_s
8
+ # param["key"] == param[:key]
9
+ #
10
+ # Every methods present in {Hash} are usable in {Param}.
11
+ class Cookies < Params
12
+
13
+ # @param hash [Hash] hash containing the parameters
14
+ def initialize(hash={})
15
+ raise ArgumentError, "the first argument must be a Hash" unless hash.is_a? Hash
16
+ # TODO: take care of the path
17
+ @hash = Hash[hash.map{|k,v| [k.to_s, {content: v, path: "/"}]}]
18
+ end
19
+
20
+ def method_missing m, *a
21
+ @hash.send(m, *(a.map(&:to_s)))
22
+ @hash.send(m, *a)
23
+ end
24
+
25
+ def [] i
26
+ @hash[i.to_s][:content]
27
+ end
28
+
29
+ def []= i, v, path="/"
30
+ @hash[i.to_s] = {content: v.to_s, path: path.to_s}
31
+ end
32
+
33
+ def path i
34
+ @hash[i.to_s][:path]
35
+ end
36
+
37
+ def set_path i, v
38
+ raise InvalidPath, v unless v.is_a? String
39
+ @hash[i.to_s][:path] = URI.encode(v)
40
+ end
41
+
42
+ def to_h
43
+ return @hash
44
+ end
45
+ alias :to_hash :to_h
46
+
47
+ def to_s
48
+ return to_h.to_s
49
+ end
50
+
51
+ end
52
+ end
@@ -17,9 +17,9 @@ end
17
17
  # if the client request match with the verb and the url provided.
18
18
  #
19
19
  # Checkout the documentation about the parameters and API for more informations
20
- def add_route(verb, url=nil, what)
20
+ def add_route(verb, option_url=nil, what)
21
21
  raise InvalidRoute, "what must be a hash" unless what.is_a? Hash
22
- what[:url] ||= url
22
+ what[:url] ||= option_url
23
23
  Array(what[:url]).each do |url|
24
24
  route = what.dup
25
25
  route[:url] = url
@@ -41,7 +41,7 @@ module Nephos
41
41
  end
42
42
 
43
43
  def error_custom(req, code, default=nil)
44
- if File.exists? "app/#{code}.html"
44
+ if File.exist? "app/#{code}.html"
45
45
  @responder.render(status: code, html: File.read("app/#{code}.html"))
46
46
  else
47
47
  render_error(req, code, default || "Error: #{req.status}")
@@ -83,7 +83,8 @@ module Nephos
83
83
  # puts "--- Params #{params.class} ---", "<<", params, ">>"
84
84
  resp = render(params)
85
85
  controller.cookies.to_h.each do |k, v|
86
- resp.set_cookie k, v
86
+ resp.set_cookie k, v[:content]
87
+ resp.header["Set-Cookie"] += ";path=" + v[:path]
87
88
  end
88
89
  return resp
89
90
  end
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.files = %w(
10
10
  lib/nephos-server.rb
11
11
  lib/nephos-server/basic_errors.rb
12
+ lib/nephos-server/cookies.rb
12
13
  lib/nephos-server/bin-helpers.rb
13
14
  lib/nephos-server/controller.rb
14
15
  lib/nephos-server/params.rb
data/routes.rb CHANGED
@@ -25,3 +25,5 @@ get url: "/get_cookies", controller: "MainController", method: "get_cookies"
25
25
  get url: "/add_cookie", controller: "MainController", method: "add_cookie"
26
26
 
27
27
  get "/err500", controller: "MainController", method: "err500"
28
+
29
+ get "/;/cookie", to: "MainController#root"
@@ -33,7 +33,7 @@ class TestController < Test::Unit::TestCase
33
33
  router = Nephos::Router.new(silent: true)
34
34
  r = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/add_cookie"})
35
35
  out = router.execute(r)
36
- assert_equal "UN_COOKIE_VAUT%3A=UN+BON+MOMENT+%21", out.header["Set-Cookie"]
36
+ assert_equal "UN_COOKIE_VAUT%3A=UN+BON+MOMENT+%21;path=/", out.header["Set-Cookie"]
37
37
  end
38
38
 
39
39
  end
@@ -5,8 +5,8 @@ class TestNephosServerGenerator < Test::Unit::TestCase
5
5
 
6
6
  `./bin/nephos-generator --test -a /tmp/nephos-server-test --no-build --no-git`
7
7
  assert(Dir.exists? "/tmp/nephos-server-test")
8
- assert(File.exists? "/tmp/nephos-server-test/Gemfile")
9
- assert(File.exists? "/tmp/nephos-server-test/routes.rb")
8
+ assert(File.exist? "/tmp/nephos-server-test/Gemfile")
9
+ assert(File.exist? "/tmp/nephos-server-test/routes.rb")
10
10
  assert(Dir.exists? "/tmp/nephos-server-test/app")
11
11
  gemfile_data = File.read("/tmp/nephos-server-test/Gemfile").split("\n")
12
12
  assert(gemfile_data.include? "gem 'nephos'")
@@ -18,14 +18,14 @@ class TestNephosServerGenerator < Test::Unit::TestCase
18
18
 
19
19
  `./bin/nephos-generator --test -a /tmp/nephos-server-test --no-git`
20
20
  assert(Dir.exists? "/tmp/nephos-server-test")
21
- assert(File.exists? "/tmp/nephos-server-test/Gemfile")
22
- assert(File.exists? "/tmp/nephos-server-test/routes.rb")
21
+ assert(File.exist? "/tmp/nephos-server-test/Gemfile")
22
+ assert(File.exist? "/tmp/nephos-server-test/routes.rb")
23
23
  assert(Dir.exists? "/tmp/nephos-server-test/app")
24
24
  gemfile_data = File.read("/tmp/nephos-server-test/Gemfile").split("\n")
25
25
  assert(gemfile_data.include? "gem 'nephos'")
26
26
 
27
27
  # if connected to internet only
28
- assert(File.exists? "/tmp/nephos-server-test/Gemfile.lock")
28
+ assert(File.exist? "/tmp/nephos-server-test/Gemfile.lock")
29
29
  gemfile_lock_data = File.read("/tmp/nephos-server-test/Gemfile.lock").split
30
30
  assert(gemfile_lock_data.include? "nephos")
31
31
  assert(gemfile_lock_data.include? "nephos-server")
@@ -37,17 +37,17 @@ class TestNephosServerGenerator < Test::Unit::TestCase
37
37
  `rm -f app/test_controller.rb`
38
38
 
39
39
  `./bin/nephos-generator --test -c test`
40
- assert File.exists? "app/test_controller.rb"
40
+ assert File.exist? "app/test_controller.rb"
41
41
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
42
42
  `rm -f app/test_controller.rb`
43
43
 
44
44
  `./bin/nephos-generator -c test --test`
45
- assert File.exists? "app/test_controller.rb"
45
+ assert File.exist? "app/test_controller.rb"
46
46
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
47
47
  `rm -f app/test_controller.rb`
48
48
 
49
49
  `./bin/nephos-generator -c testController --test`
50
- assert File.exists? "app/test_controller.rb"
50
+ assert File.exist? "app/test_controller.rb"
51
51
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
52
52
  `rm -f app/test_controller.rb`
53
53
  end
@@ -18,13 +18,13 @@ class TestGlobal < Test::Unit::TestCase
18
18
  r = open("http://127.0.0.1:8080/")
19
19
  assert_equal "{\"list\":[],\"add\":\"/add\",\"rm\":\"/rm\"}\n", r.read
20
20
  assert_equal "application/json; charset=UTF-8", r.meta["content-type"]
21
- assert_equal "a=b", r.meta["set-cookie"]
21
+ assert_equal "a=b;path=/", r.meta["set-cookie"]
22
22
  assert_equal ["200", "OK"], r.status
23
23
 
24
24
  r = open("http://127.0.0.1:8080/home")
25
25
  assert_equal "{\"list\":[],\"add\":\"/add\",\"rm\":\"/rm\"}\n", r.read
26
26
  assert_equal "application/json; charset=UTF-8", r.meta["content-type"]
27
- assert_equal "a=b", r.meta["set-cookie"]
27
+ assert_equal "a=b;path=/", r.meta["set-cookie"]
28
28
  assert_equal ["200", "OK"], r.status
29
29
 
30
30
  r = open("http://127.0.0.1:8080/home/")
data/version CHANGED
@@ -1 +1 @@
1
- 0.6.9
1
+ 0.7.0
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.9
4
+ version: 0.7.0
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-11-06 00:00:00.000000000 Z
34
+ date: 2015-11-07 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nomorebeer
@@ -122,6 +122,7 @@ files:
122
122
  - lib/nephos-server/basic_errors.rb
123
123
  - lib/nephos-server/bin-helpers.rb
124
124
  - lib/nephos-server/controller.rb
125
+ - lib/nephos-server/cookies.rb
125
126
  - lib/nephos-server/params.rb
126
127
  - lib/nephos-server/router/helpers.rb
127
128
  - lib/nephos-server/router/load.rb
@@ -168,6 +169,12 @@ rubyforge_project:
168
169
  rubygems_version: 2.4.8
169
170
  signing_key:
170
171
  specification_version: 4
171
- summary: "* Update urls and links * Important fix for cookies"
172
+ summary: "* fix regression on empty response * add unitary tests * improve gemspec
173
+ * fix severe regression on responder * fix environment bug * add continuous integration
174
+ with gitlab * fix executables requirements to be testable * add cookies management
175
+ * fix regression on content-type from v0.4 * fix nephos gem (binaries can be used
176
+ out of an application) * improve code documentation (annotations above the methods
177
+ and classes) * fix content type for json to application/json * improve executables:
178
+ version taking in count"
172
179
  test_files: []
173
180
  has_rdoc:
metadata.gz.sig CHANGED
Binary file