nephos-server 0.4.8 → 0.5.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: 6c35f4d2f0547725d90cc6f979151bc978d41670
4
- data.tar.gz: c65b023117aa32ab0ce732b9c0073f315b50ce5c
3
+ metadata.gz: 829761db1101c722504e7778ec2cd55f8edca2d1
4
+ data.tar.gz: 16741f9f42c3754172f69b43fdec9d1c07449d90
5
5
  SHA512:
6
- metadata.gz: 63d465d46581d22542a6dbfd4a7d7caf159080ef7e1d5d0a2e732bb774c86d1b9b2f53ce27140054a10301061c04d89a92cf41f41603cb86aa4ab470008b5033
7
- data.tar.gz: 146add81a36a974479ab84d57be331c8e48e2e1137c84cdd1c860a66c1d727b166649a582d316b0b57cd4f31086b2a76ac0f5adc4bd9a794b44d5f9b0fd4c3ed
6
+ metadata.gz: 9236bd2cc50a63baed30ad1c092bcb17b8d2863c40d09dce2d0e605f3a91b457d13738f7036ce7961a98135604095a6857298a866bfa9879f9d783f39439d7bf
7
+ data.tar.gz: 345df24516023c3b0d5417a77ab4a86a75e0cc33f353c6d582c5bb8c64a3ecb3a3b52dcef13d97c1b61e3e523f5d7da97588e40c653fd0870f7a1ba29a0b6860
data/CHANGELOG CHANGED
@@ -1,120 +1,82 @@
1
- v0.4.7
1
+ v0.5.0
2
+ * improve executables: version taking in count
3
+
4
+ v0.4
5
+ * fix route matching
6
+ * improve generator (help and display)
7
+ * improve generator (usage of optparser)
8
+ * improve documentation (and update)
9
+ * change generator option --debug with --test
10
+ * add lot of unitary tests on router
11
+ * add test on application generator
12
+ * add generator option (--no-build, --no-git, ...)
2
13
  * fix parameters
3
-
4
- v0.4.7
5
14
  * improve controller generator (names)
6
15
  * add puma to change the default web server
7
16
  * add environments
8
-
9
- v0.4.6
10
17
  * improve router errors
11
18
  * improve documentation (production mode)
12
19
  * add listen network parameter to run the server
13
-
14
- v0.4.5
15
20
  * fix server executable
16
-
17
- v0.4.4
18
21
  * improve errors
19
22
  * fix unitary tests about controller generator
20
-
21
- v0.4.3
22
23
  * improve gemspec changelog
23
24
  * improve generator
24
25
  * improve responder (with integer argument)
25
26
  * fix router helpers
26
-
27
- v0.4.2
28
27
  * add version to code
29
28
  * fix a file permissions
30
29
  * add generator route --rm
31
30
  * add test for generator (routes and route --rm)
32
31
  * improve routes generator with a 4th optional argument
33
-
34
- v0.4.1
35
32
  * fix regression for binary with --debug feature
36
33
  * improve routes generator
37
-
38
- v0.4.0
39
34
  * add nephos-status executable
40
35
  * add nephos-generator route option
41
36
 
42
- v0.3.2
37
+ v0.3
43
38
  * fix gem
44
39
  * add tests for generator
45
-
46
- v0.3.1
47
40
  * fix controller parameters
48
41
  * add new unitary tests
49
-
50
- v0.3.0
51
42
  * improve documentation (and fix it)
52
43
  * add documentation (guide for slim, sequel, generator)
53
44
 
54
- v0.2.4
45
+ v0.2
55
46
  * improve global coherence (file, class, consts names)
56
47
  * rename directory "controllers/" -> "app/"
57
-
58
- v0.2.3
59
48
  * add class params
60
49
  * change file place (controller)
61
50
  * improve controller
62
51
  * add unitary tests (params, controller)
63
-
64
- v0.2.2
65
52
  * minor fix bug
66
-
67
- v0.2.0
68
53
  * add documentation
69
54
 
70
- v0.1.12
55
+ v0.1
71
56
  * fix regressions from v0.1.11 and previous (routing)
72
57
  * add complet unitary tests (rendering)
73
58
  * add partial unitary tests (routing)
74
59
  * update gemspec
75
60
  * factorize some code
76
-
77
- v0.1.11
78
61
  * fix regressions from v0.1.10
79
62
  * improve rendering code
80
-
81
- v0.1.10
82
63
  * improve status content
83
64
  * add url's parameters like /u/:param
84
-
85
- v0.1.9
86
65
  * minor fixes
87
66
  * improve exceptions
88
67
  * improve generator
89
-
90
- v0.1.8
91
68
  * improve rendering
92
69
  * add html rendering
93
70
  * improve documentation
94
71
  * improve exceptions
95
-
96
- v0.1.7
97
72
  * improve routing error
98
-
99
- v0.1.6
100
73
  * fix documentation
101
-
102
- v0.1.5
103
74
  * improve routing (resource and matching)
104
-
105
- v0.1.4
106
75
  * improve routing
107
-
108
- v0.1.3
109
76
  * improve generators (errors and arguments)
110
-
111
- v0.1.2
112
77
  * fix procfile
113
-
114
- v0.1.1
115
78
  * rename src to controllers
116
79
  * improve generator
117
- v0.1
118
80
  * basic routing, rendering, and controllers
119
81
  * valid gemspec
120
82
  * basic working server
data/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  [![GitHub version](https://badge.fury.io/gh/pouleta%2FNephosRubyServer.svg)](http://badge.fury.io/gh/pouleta%2FNephosRubyServer)
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/nephos-server.svg)](http://badge.fury.io/rb/nephos-server)
5
+ [![Gem Version](https://badge.fury.io/rb/nserver.svg)](http://badge.fury.io/rb/nserver)
6
6
 
7
7
  [![Code Climate](https://codeclimate.com/github/pouleta/NephosRubyServer/badges/gpa.svg)](https://codeclimate.com/github/pouleta/NephosRubyServer)
8
8
 
9
9
  This is a minimal web server, based on [rack](TODO LINK) and [puma](TODO LINK).
10
10
  It is written in ruby. It also gives you a minimal architecture
11
- to speed up your application creation.
11
+ to speed up your application bootstrap.
12
12
 
13
13
  Features provided:
14
14
 
@@ -16,23 +16,23 @@ Features provided:
16
16
  - Render: easier render content to the client.
17
17
  - Router: create a robust and simple routing system, with url variables.
18
18
 
19
- Features wich will not be provided by nephos-server:
19
+ Features which will not be provided by nserver:
20
20
 
21
- - Templating (HTML with variables, loops, ...): It already exists and they are easy to implement.
21
+ - Templating (HTML with variables, loops, ...): It already exists and it is easy to implement.
22
22
  - [Slim](DOCUMENTATION/TEMPLATING/SLIM.md)
23
- - Database orm and connector: It already exists and simple to implement
23
+ - Database orm and connector: It already exists and simple to implement too.
24
24
  - [Sequel](DOCUMENTATION/DATABASE/SEQUEL.md)
25
25
 
26
26
  # Start
27
27
 
28
28
  ```sh
29
- gem install nephos-server # download the server
30
- nephos-generator application MyApp # generate the application
29
+ gem install nephos # download the server and executables
30
+ ngenerator application MyApp # generate the application
31
31
  cd MyApp # go in
32
- nephos-server -p 8080 -h 0.0.0.0 # start the server. port is not required, neither host
32
+ nserver -p 8080 -h 0.0.0.0 # start the server. port is not required, neither host
33
33
  ```
34
34
 
35
- ``nephos-server`` is a binary designed to start the server easly. It can take few arguments, all optionnal:
35
+ ``nserver`` is an executable designed to start the server easly. It can take few arguments, all optionnal:
36
36
 
37
37
  - ``-p``: port to listen
38
38
  - ``-h``: host to listen (network address)
@@ -53,13 +53,14 @@ Theses guides will provide you knowlegde about everything you can use in the app
53
53
 
54
54
  ### Production
55
55
 
56
- To avoid information leaks from your application, set the environment variable ``export ENVIRONMENT=production``.
56
+ To avoid information leaks from your application, set the environment variable ``export ENVIRONMENT=production``,
57
+ or run the server with ``-e production`` parameter.
57
58
  It will disable ruby error messages when an error occurs in the controller.
58
59
 
59
60
  ### Controller
60
61
 
61
62
  To create a controller, add a ruby file to ``app/``, with a class inherited by ``Nephos::Controller``
62
- The basic code of a controller can be generated via ``nephos-generator controller NAME``.
63
+ The basic code of a controller can be generated via ``ngenerator controller NAME``.
63
64
 
64
65
  ```ruby
65
66
  class Example < Nephos::Controller
@@ -91,28 +92,23 @@ return :empty
91
92
  ### Routing
92
93
 
93
94
  The routing (rules to execute the action the user wants), you have to write the ``/routes.rb`` file.
94
- if the user try to access to an url not described in the file, it will automaticaly render a 404 not found.
95
+ If the user try to access an url not described in the file, it will automaticaly render a 404 not found.
95
96
 
96
97
  ```ruby
97
98
  get url: "/", controller: "MainController", method: "root" # /
98
- get url: "/add", controller: "MainController", method: "add_url" # /add
99
- get url: "/add/:url", controller: "MainController", method: "add_url" # /add with parameter :url
100
- get url: "/rm", controller: "MainController", method: "rm_url" # /rm
101
- get url: "/rm/:url", controller: "MainController", method: "rm_url" # /rm with parameter :url
99
+ post url: "/add", controller: "MainController", method: "add_url" # /add
100
+ post url: "/add/:url", controller: "MainController", method: "add_url" # /add with parameter :url
101
+ put url: "/rm", controller: "MainController", method: "rm_url" # /rm
102
+ put url: "/rm/:url", controller: "MainController", method: "rm_url" # /rm with parameter :url
102
103
  resource "infos" do
103
104
  get url: "/", controller: "MainController", method: "root" # generate /infos
104
- get url: "/abbout", controller: "MainController", method: "root" # generate /infos/about
105
+ get url: "/about", controller: "MainController", method: "root" # generate /infos/about
105
106
  end
106
107
  ```
107
108
 
108
109
 
109
110
  # Developers: Roadmap
110
111
 
111
- ## TODO v0.4
112
- - improve generator with application tests
113
- - improve executables (tests, arguments)
114
- - improve documentation (bin)
115
-
116
112
  ## TODO v0.5
117
113
  - executables with version
118
114
  - cookies, ...
@@ -121,6 +117,8 @@ end
121
117
  ## TODO v0.6
122
118
  - startable as daemon
123
119
  - hooks for controller
120
+ - feature to change HTTP header from controller
121
+ - customisable default 404 errors and 500 errors
124
122
 
125
123
  ## v1 requierements
126
124
  - Environement, Daemons, Port, Listen Host, Routables, Arguments
data/app/main.rb CHANGED
@@ -11,7 +11,7 @@ class MainController < Nephos::Controller
11
11
  end
12
12
 
13
13
  def add_url
14
- url = arguments["url"]
14
+ url = params["url"]
15
15
  if url
16
16
  Dataset << url
17
17
  return {plain: "#{url} added"}
@@ -21,7 +21,7 @@ class MainController < Nephos::Controller
21
21
  end
22
22
 
23
23
  def rm_url
24
- url = arguments[:url]
24
+ url = params[:url]
25
25
  if url
26
26
  Dataset.rm url
27
27
  return {plain: "#{url} removed"}
data/bin/nephos-generator CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'colorize'
4
4
  require 'optparse'
5
+
6
+ require 'nephos-server/version'
5
7
  require 'nephos-server/bin-helpers'
6
8
 
7
9
  GEMFILE = <<EOF
@@ -17,8 +19,8 @@ ROUTE_RB = <<EOF
17
19
  EOF
18
20
 
19
21
  def raise_invalid_appli
20
- if not Nephos::Bin.is_a_valid_application? and not $debug
21
- raise "You are not in a valid application directory"
22
+ if not Nephos::Bin.is_a_valid_application? and not $test
23
+ raise BinError, "You are not in a valid application directory"
22
24
  end
23
25
  end
24
26
 
@@ -39,11 +41,11 @@ module Nephos
39
41
 
40
42
  def self.generate!(verb, url, dest_c, dest_m=nil)
41
43
  raise_invalid_appli
42
- raise InvalidVerb, "\"#{verb}\" doesn't match with /\w+/" if not verb.to_s.match(/^\w+$/)
43
- raise InvalidUrl if not url.match(/^\/?(:?\w+)(\/:?\w+)*\/?$/)
44
- raise "Option dest_c must match with \"controller#method\"" if not dest_c.match(/^\w+\#\w+$/) and dest_m.nil?
45
- raise "Option dest_c must match with \"controllerName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
46
- raise "Option dest_m must match with \"methodName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
44
+ raise BinError, "\"#{verb}\" doesn't match with /\w+/" if not verb.to_s.match(/^\w+$/)
45
+ raise BinError, "\"#{url}\" is not a valid url" if not url.match(/^\/?(:?\w+)(\/:?\w+)*\/?$/)
46
+ raise BinError, "Option dest_c must match with \"controller#method\"" if not dest_c.match(/^\w+\#\w+$/) and dest_m.nil?
47
+ raise BinError, "Option dest_c must match with \"controllerName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
48
+ raise BinError, "Option dest_m must match with \"methodName\"" if not dest_m.nil? and not dest_c.match(/^\w+$/)
47
49
  controller, method = dest_c, dest_m
48
50
  if dest_m.nil?
49
51
  controller = dest_c.split("#")[0]
@@ -54,14 +56,14 @@ module Nephos
54
56
  if exists? line
55
57
  if $remove
56
58
  routes = File.read("routes.rb").split("\n")
57
- puts "Route deleted: ".green + routes.delete(line).to_s
59
+ puts "Success: ".green + "Route deleted: " + routes.delete(line).to_s
58
60
  File.write("routes.rb", routes.join("\n") + "\n")
59
61
  else
60
- puts("Route already exists: ".yellow + line)
62
+ puts("Warning: ".yellow + "Route already exists: " + line)
61
63
  end
62
64
  else
63
65
  if $remove
64
- puts("Route doesn't exists: ".yellow + line)
66
+ puts("Warning: ".yellow + "Route doesn't exists: " + line)
65
67
  else
66
68
  write!(line)
67
69
  end
@@ -75,26 +77,35 @@ module Nephos
75
77
  lname = uname.gsub(/([A-Z])/, '_\1')[1..-1].downcase
76
78
  file = "app/#{lname}.rb"
77
79
  raise_invalid_appli
78
- if File.exists? file
79
- print "The file #{file} already exists. Are you sure to erase it ? (y/N)"
80
- r = STDIN.gets.to_s.chomp
81
- raise "File #{file} already exists" unless r.match(/y(es)?/)
82
- end
83
- f = File.open(file, 'w')
84
- f << <<EOF
80
+ if $remove
81
+ if File.exists?(file) and File.read(file).include? "class #{uname} < Nephos::Controller"
82
+ File.delete(file)
83
+ puts "Success: ".yellow + "\"#{file}\" removed"
84
+ else
85
+ raise BinError, "\"#{file}\" is not a valid Controller file."
86
+ end
87
+ else
88
+ if File.exists? file
89
+ print "Warning: ".yellow + "The file #{file} already exists. Are you sure to erase it ? (y/N) : "
90
+ r = STDIN.gets.to_s.chomp
91
+ raise BinError, "File #{file} already exists" unless r.match(/y(es)?/)
92
+ end
93
+ f = File.open(file, 'w')
94
+ f << <<EOF
85
95
  class #{uname} < Nephos::Controller
86
96
  def root
87
97
  return {plain: "index"}
88
98
  end
89
99
  end
90
100
  EOF
91
- puts "Controller \"#{name}\" created at location \"#{file}\""
101
+ puts "Success: ".green + "Controller \"#{uname}\" created at location \"#{file}\""
102
+ end
92
103
  end
93
104
  end
94
105
 
95
106
  module Application
96
107
  def self.create_application_dir dir
97
- raise "Directory #{dir} already exists" if Dir.exists? dir
108
+ raise BinError, "Directory #{dir} already exists" if Dir.exists? dir
98
109
  Dir.mkdir dir
99
110
  end
100
111
 
@@ -103,7 +114,7 @@ EOF
103
114
  end
104
115
 
105
116
  def self.initialize!
106
- raise "Not an empty dir" unless Dir[File.expand_path "*"].empty?
117
+ raise BinError, "Not an empty dir" unless Dir[File.expand_path "*"].empty?
107
118
  File.write "routes.rb", ROUTE_RB
108
119
  File.write "Gemfile", GEMFILE
109
120
  Dir.mkdir "app"
@@ -111,34 +122,32 @@ EOF
111
122
  `git init .`
112
123
  puts "Git repository initialized"
113
124
  rescue Errno::ENOENT => err
114
- puts "Warning: git repository not initialized"
125
+ puts "Git Init Error: ".yellow + "git repository not initialized"
115
126
  rescue => err
116
- puts "Error: #{err.message}"
117
- end
118
- exec("bundle install")
127
+ puts "Git Init Error: ".yellow + " #{err.message}"
128
+ end if $git
129
+ exec("bundle install") if $build
119
130
  end
120
131
  end
121
132
 
122
133
  def self.main opt
123
- case opt[0]
124
- when "c", "controller"
125
- if opt[1].to_s.match(/[\w\-\.]+/)
126
- Controller.generate!(opt[1])
127
- else
128
- puts "error"
129
- end
130
- when "a", "appli", "application"
131
- if not opt[1].to_s.empty?
132
- Application.create_application_dir(opt[1])
133
- puts "Application #{opt[1]} created"
134
- Application.move_to_application_dir(opt[1])
134
+ case $mode
135
+ when :controller
136
+ raise BinError, "Invalid Controller name" if not opt[0].to_s.match(/[\w\-\.]+/)
137
+ Controller.generate!(opt[0])
138
+ when :application
139
+ if not opt[0].to_s.empty?
140
+ Application.create_application_dir(opt[0])
141
+ puts "Application #{opt[0]} created"
142
+ Application.move_to_application_dir(opt[0])
135
143
  end
136
144
  Application.initialize!
137
145
  puts "Application initialized"
138
- when "r", "route"
139
- Route.generate!(*(opt[1..4]))
146
+ when :route
147
+ raise BinError, "Need more arguments (verb url controller method)" if opt.size < 3
148
+ Route.generate!(*(opt[0..3]))
140
149
  else
141
- puts "\"#{opt[0]}\" not recognized has a command"
150
+ puts "nephos-generator --help"
142
151
  end
143
152
  end
144
153
 
@@ -147,19 +156,48 @@ end
147
156
 
148
157
  begin
149
158
  opt = OptionParser.new do |opts|
150
- opts.banner = "Usage: nephos-generator [controller name] [appli [name]]"
159
+ opts.banner = "Usage<#{Nephos::VERSION}>: nephos-generator <options>"
160
+
161
+ $git = true
162
+ opts.on("--no-git", "Disable the git initialization when create new application") do
163
+ $git = false
164
+ end
151
165
 
152
- opts.on("--rm") do
166
+ $build = true
167
+ opts.on("--no-build", "Disable the `bundle install` execution when create new application") do
168
+ $build = false
169
+ end
170
+
171
+ opts.on("--application", "-a", "Create new application") do
172
+ $mode = :application
173
+ end
174
+
175
+ opts.on("--route", "-r", "Create and remove routes") do
176
+ $mode = :route
177
+ end
178
+
179
+ opts.on("--controller", "-c", "Create and remove controller") do
180
+ $mode = :controller
181
+ end
182
+
183
+ opts.on("--rm", "Remove") do
153
184
  $remove = true
154
185
  end
155
186
 
156
- opts.on("--debug") do
187
+ opts.on("--debug", "Enable debugging mode") do
157
188
  $debug = true
158
189
  end
190
+
191
+ opts.on("--test", "Enable testing mode (for nephos developpers)") do
192
+ $test = true
193
+ end
159
194
  end.parse!
160
195
 
161
196
  Nephos::Generator.main(opt)
162
197
 
198
+ rescue BinError => err
199
+ puts "Error:".red + " #{err.message}"
200
+
163
201
  rescue => err
164
202
  puts "Error:".red + " #{err.message}"
165
203
  puts err.backtrace
data/bin/nephos-server CHANGED
@@ -3,14 +3,17 @@
3
3
  require 'colorize'
4
4
  require 'optparse'
5
5
 
6
+ require 'nephos-server/version'
7
+ require 'nephos-server/bin-helpers'
8
+
6
9
  class RoutingError < StandardError; end
7
10
 
8
11
  begin
9
12
  OptionParser.new do |opts|
10
- opts.banner = "Usage: nephos-server [-p=port] [-h=listen] [--debug]"
13
+ opts.banner = "Usage<#{Nephos::VERSION}>: nephos-server <options>"
11
14
 
12
15
  $server_port = ENV["SERVER_PORT"] || 8080
13
- opts.on("-p=nb", "--port=nb", "Port") do |port|
16
+ opts.on("-p=nb", "--port=nb", "Port to listen") do |port|
14
17
  $server_port = Integer(port)
15
18
  end
16
19
 
@@ -24,18 +27,22 @@ begin
24
27
  $server_env = env
25
28
  end
26
29
 
27
- opts.on("--debug") do
30
+ opts.on("--debug", "Enable debugging mode") do
28
31
  $debug = true
29
32
  end
33
+
34
+ opts.on("--test", "Enable testing mode (for nephos developpers)") do
35
+ $test = true
36
+ end
30
37
  end.parse!
31
38
 
32
- if $debug
39
+ if $test
33
40
  require_relative "../lib/nephos-server"
34
41
  else
35
42
  require 'nephos-server'
36
43
  end
37
44
 
38
- if not $debug and
45
+ if not $test and
39
46
  (not File.exists? "Gemfile.lock" or
40
47
  not File.read("Gemfile.lock").split.index("nephos-server"))
41
48
  raise InvalidApplication
data/bin/nephos-status CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
+
5
+ require 'nephos-server/version'
4
6
  require 'nephos-server/bin-helpers'
5
7
 
6
8
  opt = OptionParser.new do |opts|
7
- opts.banner = "Usage: nephos-status [appli directory]"
9
+ opts.banner = "Usage<#{Nephos::VERSION}>: nephos-status [appli directory]"
8
10
 
9
11
  opts.on("--rm") do
10
12
  $remove = true
@@ -11,3 +11,5 @@ module Nephos
11
11
 
12
12
  end
13
13
  end
14
+
15
+ class BinError < StandardError; end
@@ -10,7 +10,7 @@ module Nephos
10
10
 
11
11
  def self.add_params!(what)
12
12
  params = what[:url].split('/').map do |p|
13
- p.match(/:\w+/) ? {p: "[[:graph:]]+", name: p} : {p: p, name: nil}
13
+ p.match(/:\w+/) ? {p: "[^\/]+", name: p} : {p: p, name: nil}
14
14
  end
15
15
  url = params.map{|e| e[:p]}.join("/")
16
16
  url = "/" if url.empty?
@@ -0,0 +1,9 @@
1
+ module Nephos
2
+ VERSION_FILE = __FILE__.split("/")[0..-4].join("/") + "/version"
3
+ VERSION = File.read(VERSION_FILE).strip
4
+
5
+ @@env = $server_env
6
+ def self.env
7
+ @@env
8
+ end
9
+ end
data/lib/nephos-server.rb CHANGED
@@ -6,6 +6,8 @@ require 'open-uri'
6
6
  require 'rack'
7
7
  require 'colorize'
8
8
 
9
+ require_relative 'nephos-server/version'
10
+
9
11
  # lib
10
12
  require_relative 'nephos-server/basic_errors'
11
13
  require_relative 'nephos-server/params'
@@ -13,13 +15,3 @@ require_relative 'nephos-server/controller'
13
15
  require_relative 'nephos-server/router/main'
14
16
  # server
15
17
  require_relative 'nephos-server/server/main'
16
-
17
- module Nephos
18
- VERSION_FILE = __FILE__.split("/")[0..-3].join("/") + "/version"
19
- VERSION = File.read(VERSION_FILE).strip
20
-
21
- @@env = $server_env
22
- def self.env
23
- @@env
24
- end
25
- end
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = 'poulet_a@epitech.eu',
11
11
  s.files = %w(
12
12
  lib/nephos-server.rb
13
+ lib/nephos-server/version.rb
13
14
  lib/nephos-server/basic_errors.rb
14
15
  lib/nephos-server/params.rb
15
16
  lib/nephos-server/controller.rb
@@ -51,6 +52,7 @@ nephos-status
51
52
  #s.cert_chain = ['certs/poulet_a.pem']
52
53
  #s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
53
54
 
55
+ # s.add_dependency 'nephos', '~> 1.0'
54
56
  s.add_dependency 'nomorebeer', '~> 1.1'
55
57
  s.add_dependency 'rack', '~> 1.6'
56
58
  s.add_dependency 'colorize', '~> 0.7'
data/routes.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  resource "home" do
2
2
  resource "/index" do
3
3
  get url: "/", controller: "MainController", method: "root"
4
- get url: "/add", controller: "MainController", method: "add_url"
5
- get url: "/rm", controller: "MainController", method: "rm_url"
4
+ post url: "/add", controller: "MainController", method: "add_url"
5
+ put url: "/rm", controller: "MainController", method: "rm_url"
6
6
  end
7
7
  get url: "/", controller: "MainController", method: "root"
8
8
  end
data/test/generator.rb CHANGED
@@ -1,25 +1,32 @@
1
1
  class TestNephosServerGenerator < Test::Unit::TestCase
2
2
 
3
3
  def test_generator_application
4
- # Dir.chdir("/tmp")
5
- # name = Time.now.to_i.to_s
6
- # `nephos-server a #{name}`
4
+ `rm -rf /tmp/nephos-server-test 2> /tmp/null`
5
+
6
+ `./bin/nephos-generator -a /tmp/nephos-server-test --no-build --no-git`
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")
10
+ assert(Dir.exists? "/tmp/nephos-server-test/app")
11
+ gemfile_data = File.read("/tmp/nephos-server-test/Gemfile").split("\n")
12
+ assert(gemfile_data.include? "gem 'nephos-server'")
13
+ `rm -rf /tmp/nephos-server-test 2> /tmp/null`
7
14
  end
8
15
 
9
16
  def test_generator_controller
10
17
  `rm -f app/test_controller.rb`
11
18
 
12
- `nephos-generator --debug c test`
19
+ `./bin/nephos-generator --test -c test`
13
20
  assert File.exists? "app/test_controller.rb"
14
21
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
15
22
  `rm -f app/test_controller.rb`
16
23
 
17
- `nephos-generator c test --debug`
24
+ `./bin/nephos-generator -c test --test`
18
25
  assert File.exists? "app/test_controller.rb"
19
26
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
20
27
  `rm -f app/test_controller.rb`
21
28
 
22
- `nephos-generator c testController --debug`
29
+ `./bin/nephos-generator -c testController --test`
23
30
  assert File.exists? "app/test_controller.rb"
24
31
  assert_equal "class TestController < Nephos::Controller", File.read("app/test_controller.rb").split("\n").first
25
32
  `rm -f app/test_controller.rb`
@@ -28,9 +35,9 @@ class TestNephosServerGenerator < Test::Unit::TestCase
28
35
  # test simple and rm
29
36
  def test_generator_route1
30
37
  s1 = File.read("routes.rb")
31
- `./bin/nephos-generator --debug r get test ctr#mth`
38
+ `./bin/nephos-generator --test -r get test ctr#mth`
32
39
  s2 = File.read("routes.rb")
33
- `./bin/nephos-generator --debug r get test ctr#mth --rm`
40
+ `./bin/nephos-generator --test -r get test ctr#mth --rm`
34
41
  s3 = File.read("routes.rb")
35
42
  assert_equal s1, s3
36
43
  assert_not_equal s1, s2
@@ -39,11 +46,11 @@ class TestNephosServerGenerator < Test::Unit::TestCase
39
46
  # test if ctr#mth == ctr mth
40
47
  def test_generator_route2
41
48
  s1 = File.read("routes.rb")
42
- `./bin/nephos-generator --debug r get test ctr#mth`
49
+ `./bin/nephos-generator --test -r get test ctr#mth`
43
50
  s2 = File.read("routes.rb")
44
- `./bin/nephos-generator --debug r get test ctr mth`
51
+ `./bin/nephos-generator --test -r get test ctr mth`
45
52
  s3 = File.read("routes.rb")
46
- `./bin/nephos-generator --debug r get test ctr mth --rm`
53
+ `./bin/nephos-generator --test -r get test ctr mth --rm`
47
54
  s4 = File.read("routes.rb")
48
55
  assert_equal s2, s3
49
56
  assert_equal s1, s4
data/test/router.rb CHANGED
@@ -2,6 +2,12 @@ class TestController < Nephos::Controller
2
2
  def method
3
3
  {plain: "test"}
4
4
  end
5
+ def method1
6
+ {plain: "test1"}
7
+ end
8
+ def method2
9
+ {plain: "test2"}
10
+ end
5
11
  end
6
12
 
7
13
  class TestNephosServerRouter < Test::Unit::TestCase
@@ -61,7 +67,7 @@ class TestNephosServerRouter < Test::Unit::TestCase
61
67
  reset_routes!
62
68
  get url: "/:what", controller: "TestController", method: "method", silent: true
63
69
  assert_equal "/:what", first[:url]
64
- assert_equal /^\/[[:graph:]]+$/, first[:match]
70
+ assert_equal /^\/[^\/]+$/, first[:match]
65
71
  end
66
72
 
67
73
  def test_valid_resources
@@ -81,16 +87,55 @@ class TestNephosServerRouter < Test::Unit::TestCase
81
87
  get url: "/:what", controller: "TestController", method: "method", silent: true
82
88
  end
83
89
  assert_equal "/home/:what", first[:url]
84
- assert_equal /^\/home\/[[:graph:]]+$/, first[:match]
90
+ assert_equal /^\/home\/[^\/]+$/, first[:match]
85
91
  end
86
92
 
87
- def test_valid_resources_params2
93
+ def test_valid_resources_params2
88
94
  reset_routes!
89
95
  resource "/:id" do
90
96
  get url: "/show", controller: "TestController", method: "method", silent: true
91
97
  end
92
98
  assert_equal "/:id/show", first[:url]
93
- assert_equal /^\/[[:graph:]]+\/show$/, first[:match]
99
+ assert_equal /^\/[^\/]+\/show$/, first[:match]
100
+ end
101
+
102
+ def test_routing_matching_simple
103
+ reset_routes!
104
+ get url: "/index", controller: "TestController", method: "method", silent: true
105
+ post url: "/index", controller: "TestController", method: "method", silent: true
106
+ assert(Nephos::Router::parse_path(["index"], "GET"))
107
+ assert(Nephos::Router::parse_path(["index"], "POST"))
108
+ assert(Nephos::Router::parse_path(["index"], "PUT") == nil)
109
+ assert(Nephos::Router::parse_path(["indexx"], "GET") == nil)
110
+ assert(Nephos::Router::parse_path(["inde"], "GET") == nil)
111
+ end
112
+
113
+ def test_routing_matching_simple_with_arguments1
114
+ reset_routes!
115
+ get url: "/:id", controller: "TestController", method: "method1", silent: true
116
+ get url: "/:id/index", controller: "TestController", method: "method2", silent: true
117
+ assert(Nephos::Router::parse_path(["id", "index"], "GET"))
118
+ assert(Nephos::Router::parse_path(["XXX", "index"], "GET"))
119
+ assert(Nephos::Router::parse_path(["id"], "GET"))
120
+ assert(Nephos::Router::parse_path(["XXX"], "GET"))
121
+ assert(Nephos::Router::parse_path(["index", "id"], "GET") == nil)
122
+ end
123
+
124
+ def test_routing_matching_simple_with_arguments2
125
+ reset_routes!
126
+ get url: "/index", controller: "TestController", method: "method1", silent: true
127
+ get url: "/index/:id", controller: "TestController", method: "method1", silent: true
128
+ post url: "/index/:id/index", controller: "TestController", method: "method2", silent: true
129
+ assert(Nephos::Router::parse_path(["id", "index"], "GET") == nil)
130
+ assert(Nephos::Router::parse_path(["XXX", "index"], "GET") == nil)
131
+ assert(Nephos::Router::parse_path(["id"], "GET") == nil)
132
+ assert(Nephos::Router::parse_path(["XXX"], "GET") == nil)
133
+ assert(Nephos::Router::parse_path(["index", "id"], "GET"))
134
+ assert(Nephos::Router::parse_path(["index", "XXX"], "GET"))
135
+ assert(Nephos::Router::parse_path(["index", "XXX", "index"], "POST"))
136
+ assert(Nephos::Router::parse_path(["index", "XXX", "index"], "GET") == nil)
137
+ assert(Nephos::Router::parse_path(["index", "XXX", "id"], "POST") == nil)
138
+ assert(Nephos::Router::parse_path(["index", "XXX", "XXX"], "POST") == nil)
94
139
  end
95
140
 
96
141
  end
data/test/test.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require "test/unit"
2
- require_relative "../lib/nephos-server"
3
2
 
4
- class TestNephosServer < Test::Unit::TestCase
5
- end
3
+ require_relative "../lib/nephos-server"
6
4
 
7
5
  require_relative 'responder'
8
6
  require_relative 'router'
data/version CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.5.0
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.4.8
4
+ version: 0.5.0
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-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nomorebeer
@@ -71,6 +71,7 @@ description: " a minimalist server, based on rack/puma, with routing, rendering,
71
71
  email:
72
72
  - poulet_a@epitech.eu
73
73
  - - lib/nephos-server.rb
74
+ - lib/nephos-server/version.rb
74
75
  - lib/nephos-server/basic_errors.rb
75
76
  - lib/nephos-server/params.rb
76
77
  - lib/nephos-server/controller.rb
@@ -130,6 +131,7 @@ files:
130
131
  - lib/nephos-server/router/main.rb
131
132
  - lib/nephos-server/server/main.rb
132
133
  - lib/nephos-server/server/responder.rb
134
+ - lib/nephos-server/version.rb
133
135
  - nephos-server.gemspec
134
136
  - routes.rb
135
137
  - test/controller.rb
@@ -162,5 +164,5 @@ rubyforge_project:
162
164
  rubygems_version: 2.4.8
163
165
  signing_key:
164
166
  specification_version: 4
165
- summary: "* fix parameters"
167
+ summary: "* improve executables: version taking in count"
166
168
  test_files: []