nephos-server 0.2.4 → 0.3.1

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: a0c699cab58ca0ec6248b17674081ac621137843
4
- data.tar.gz: 6ac12538e8f294cefe7c1881ef5eef6a182917b2
3
+ metadata.gz: 109c4c4ca9d472b6b5f0dd35a2bf6588faacbf52
4
+ data.tar.gz: a1fc6c4863ca689e02bb6f777bd24dbbacf5de1b
5
5
  SHA512:
6
- metadata.gz: 5ff2cd7da5ee44559e590165c79c0530fdb3bf55b78a27c00f896e4c58e6106165db0d9be62669c33c6466607ff36288aef85a0ba4b191b19eb6103635d69077
7
- data.tar.gz: 12f799ef408edcc5b8ef980999a62f35d0cd3277f22af71c6c0770945e4fa23cda3b871b465e84db69832ba87773fb511b9698b5effb9a9ca25ce4096fc53d68
6
+ metadata.gz: b9c9fad3377f4107a74a3ecf94ee52b05d69b8b8b2c69d17083afcca5f0daaef7ab85bf0160092dc080326e95cd388126d2dfd7e64012fee45029bf3b190413a
7
+ data.tar.gz: c63beb9a5addc4f40bddb07628738765344ff56181782de060210caad96ebb814086a5a63e3d9a655f05baddcf2f5efeda7d7074c232480d3d73c3cf94126a3c
data/README.md CHANGED
@@ -6,21 +6,30 @@
6
6
 
7
7
  [![Code Climate](https://codeclimate.com/github/pouleta/NephosRubyServer/badges/gpa.svg)](https://codeclimate.com/github/pouleta/NephosRubyServer)
8
8
 
9
- This is a simple web server, based on rack and puma, with a minimal help:
9
+ This is a minimal web server, based on [rack](TODO LINK) and [puma](TODO LINK).
10
+ It is written in ruby. It also gives you a minimal architecture
11
+ to speed up your application creation.
10
12
 
11
- - Controllers
12
- - Rendering
13
- - Routing
13
+ Features provided:
14
14
 
15
- No templating, no database by default. They are extensions of your choice.
15
+ - Controllers: gives you a resource logic.
16
+ - Render: easier render content to the client.
17
+ - Router: create a robust and simple routing system, with url variables.
18
+
19
+ Features wich will not be provided by nephos-server:
20
+
21
+ - Templating (HTML with variables, loops, ...): It already exists and they are easy to implement.
22
+ - [Slim](DOCUMENTATION/TEMPLATING/SLIM.md)
23
+ - Database orm and connector: It already exists and simple to implement
24
+ - [Sequel](DOCUMENTATION/DATABASE/SEQUEL.md)
16
25
 
17
26
  # Start
18
27
 
19
28
  ```sh
20
- gem install nephos-server
21
- nephos-generator application MyApp
22
- cd MyApp
23
- nephos-server -p 8080 # port is not required
29
+ gem install nephos-server # download the server
30
+ nephos-generator application MyApp # generate the application
31
+ cd MyApp # go in
32
+ nephos-server -p 8080 # start the server. port is not required
24
33
  ```
25
34
 
26
35
 
@@ -28,14 +37,17 @@ nephos-server -p 8080 # port is not required
28
37
 
29
38
  ## Guides
30
39
 
31
- ### [Render API](DOCUMENTATION/API_RENDER.md)
32
- ### [Router GUIDE](DOCUMENTATION/GUIDE_ROUTER.md)
40
+ Theses guides will provide you knowlegde about everything you can use in the application.
41
+
42
+ - [Generator GUIDE](DOCUMENTATION/GUIDE_GENERATOR.md)
43
+ - [Render API](DOCUMENTATION/API_RENDER.md)
44
+ - [Router GUIDE](DOCUMENTATION/GUIDE_ROUTER.md)
33
45
 
34
46
  ## Examples
35
47
 
36
48
  ### Controller
37
49
 
38
- To create a controller, simply add a ruby code file to ``app/``, with a class inherited by ``Nephos::Controller``
50
+ To create a controller, add a ruby file to ``app/``, with a class inherited by ``Nephos::Controller``
39
51
  The basic code of a controller can be generated via ``nephos-generator controller NAME``.
40
52
 
41
53
  ```ruby
@@ -52,7 +64,7 @@ end
52
64
 
53
65
  ### Rendering
54
66
 
55
- In a controller, use:
67
+ To render a content to the client, you can return informations from a Controller method:
56
68
 
57
69
  ```ruby
58
70
  return {status: code}
@@ -66,29 +78,31 @@ return :empty
66
78
 
67
79
  ### Routing
68
80
 
69
- Like in ``/routes.rb``, you have to route manually the api.
81
+ The routing (rules to execute the action the user wants), you have to write the ``/routes.rb`` file.
82
+ if the user try to access to an url not described in the file, it will automaticaly render a 404 not found.
70
83
 
71
84
  ```ruby
72
85
  get url: "/", controller: "MainController", method: "root" # /
73
86
  get url: "/add", controller: "MainController", method: "add_url" # /add
74
- get url: "/add/:url", controller: "MainController", method: "add_url" # /add
87
+ get url: "/add/:url", controller: "MainController", method: "add_url" # /add with parameter :url
75
88
  get url: "/rm", controller: "MainController", method: "rm_url" # /rm
76
- get url: "/rm/:url", controller: "MainController", method: "rm_url" # /rm
89
+ get url: "/rm/:url", controller: "MainController", method: "rm_url" # /rm with parameter :url
77
90
  resource "infos" do
78
91
  get url: "/", controller: "MainController", method: "root" # generate /infos
92
+ get url: "/abbout", controller: "MainController", method: "root" # generate /infos/about
79
93
  end
80
94
  ```
81
95
 
82
96
 
83
97
  # Developers: Roadmap
84
98
 
85
- ## TODO v0.3
86
- - Improve documentation (fix english, increase coverage, ...)
87
- - Improve unitary test coverage
99
+ ## TODO v0.4
100
+ - improve generator with application status, tests, more generation (routing, ...)
88
101
 
89
102
  ## TODO v1
90
103
  - Improved Routing (more helper options)
91
104
  - Improved Rendering (more options)
105
+ - Customisable errors (404 noticely, and 500)
92
106
  - Guide about
93
107
  - Controllers
94
108
  - Routing
@@ -1,7 +1,7 @@
1
1
  module Nephos
2
2
  class Controller
3
3
 
4
- attr_reader :env, :infos, :callpath
4
+ attr_reader :env, :infos, :callpath, :params
5
5
 
6
6
  # @param env [Hash] env extracted from the http request
7
7
  # @param parsed [Hash] pre-parsed env with parameters, ...
@@ -16,14 +16,10 @@ module Nephos
16
16
  @infos= parsed
17
17
  @callpath= callpath
18
18
  @params= parsed[:args]
19
- @params.merge! Params.new(Hash[callpath[:params].zip @infos[:path]])
20
- @params.select!{|k,v|k}
19
+ @params.merge! Hash[callpath[:params].zip @infos[:path]]
20
+ @params.select!{|k,v| not k.to_s.empty?}
21
+ @params = Params.new(@params)
21
22
  end
22
23
 
23
- def arguments
24
- @params
25
- end
26
- alias :params :arguments
27
-
28
24
  end
29
25
  end
@@ -56,40 +56,6 @@ module Nephos
56
56
  end
57
57
  end
58
58
 
59
- def route_prefix
60
- @route_prefix ||= []
61
- File.join(["/"] + @route_prefix)
62
- end
63
-
64
- def add_route(what, verb)
65
- raise InvalidRoute unless what.is_a? Hash
66
- what[:url] = File.expand_path File.join(route_prefix, what[:url])
67
- Nephos::Router.check!(what)
68
- Nephos::Router.add_params!(what)
69
- Nephos::Router.add(what, verb)
70
- end
71
-
72
- # @param what [Hash]
73
- def get what
74
- add_route what, "GET"
75
- end
76
-
77
- # @param what [Hash]
78
- def post what
79
- add_route what, "POST"
80
- end
81
-
82
- # @param what [Hash]
83
- def put what
84
- add_route what, "PUT"
85
- end
86
-
87
- def resource(name, &block)
88
- @route_prefix ||= []
89
- @route_prefix << name
90
- block.call
91
- @route_prefix.pop
92
- end
93
-
59
+ require_relative 'helpers'
94
60
  load 'routes.rb'
95
61
  puts
data/test/controller.rb CHANGED
@@ -16,4 +16,10 @@ class TestNephosServerController < Test::Unit::TestCase
16
16
  assert_raise do Nephos::Controller.new({}, {path: [], args: nil}, {params: {}}) end
17
17
  end
18
18
 
19
+ def test_controller_params
20
+ c = Nephos::Controller.new(env={}, {path: ["value"], args: {}}, {params: ["param"]})
21
+ assert_equal "value", c.params[:param]
22
+ assert_equal "value", c.params["param"]
23
+ end
24
+
19
25
  end
data/test/router.rb CHANGED
@@ -6,13 +6,91 @@ end
6
6
 
7
7
  class TestNephosServerRouter < Test::Unit::TestCase
8
8
 
9
- # remove all seeds
10
- Nephos::Router::ROUTES = []
9
+ def reset_routes!
10
+ Nephos::Router::ROUTES.clear
11
+ end
12
+
13
+ def first
14
+ Nephos::Router::ROUTES.first
15
+ end
16
+
17
+ def test_multi_routes
18
+ reset_routes!
19
+ get url: "/a", controller: "TestController", method: "method", silent: true
20
+ get url: "/b", controller: "TestController", method: "method", silent: true
21
+ get url: "/c", controller: "TestController", method: "method", silent: true
22
+ post url: "/a", controller: "TestController", method: "method", silent: true
23
+ post url: "/b", controller: "TestController", method: "method", silent: true
24
+ post url: "/c", controller: "TestController", method: "method", silent: true
25
+ put url: "/a", controller: "TestController", method: "method", silent: true
26
+ put url: "/b", controller: "TestController", method: "method", silent: true
27
+ put url: "/c", controller: "TestController", method: "method", silent: true
28
+ assert_equal 9, Nephos::Router::ROUTES.size
29
+ assert_equal 3, Nephos::Router::ROUTES.select{ |r|
30
+ r[:verb] == "GET"
31
+ }.size
32
+ end
11
33
 
12
34
  def test_valid_routes
35
+ reset_routes!
13
36
  get url: "/", controller: "TestController", method: "method", silent: true
37
+ assert_equal "/", first[:url]
38
+ assert_equal "GET", first[:verb]
39
+ assert_equal "TestController", first[:controller]
40
+ assert_equal "method", first[:method]
41
+ assert_equal /^\/$/, first[:match]
42
+
43
+ reset_routes!
14
44
  post url: "/", controller: "TestController", method: "method", silent: true
45
+ assert_equal "/", first[:url]
46
+ assert_equal "POST", first[:verb]
47
+ assert_equal "TestController", first[:controller]
48
+ assert_equal "method", first[:method]
49
+ assert_equal /^\/$/, first[:match]
50
+
51
+ reset_routes!
15
52
  put url: "/", controller: "TestController", method: "method", silent: true
53
+ assert_equal "/", first[:url]
54
+ assert_equal "PUT", first[:verb]
55
+ assert_equal "TestController", first[:controller]
56
+ assert_equal "method", first[:method]
57
+ assert_equal /^\/$/, first[:match]
58
+ end
59
+
60
+ def test_valid_routes_params
61
+ reset_routes!
62
+ get url: "/:what", controller: "TestController", method: "method", silent: true
63
+ assert_equal "/:what", first[:url]
64
+ assert_equal /^\/[[:graph:]]+$/, first[:match]
65
+ end
66
+
67
+ def test_valid_resources
68
+ reset_routes!
69
+ resource "/home" do
70
+ assert_equal route_prefix, "/home"
71
+ end
72
+ resource "/home" do
73
+ get url: "/help", controller: "TestController", method: "method", silent: true
74
+ end
75
+ assert_equal "/home/help", first[:url]
76
+ end
77
+
78
+ def test_valid_resources_params
79
+ reset_routes!
80
+ resource "/home" do
81
+ get url: "/:what", controller: "TestController", method: "method", silent: true
82
+ end
83
+ assert_equal "/home/:what", first[:url]
84
+ assert_equal /^\/home\/[[:graph:]]+$/, first[:match]
85
+ end
86
+
87
+ def test_valid_resources_params2
88
+ reset_routes!
89
+ resource "/:id" do
90
+ get url: "/show", controller: "TestController", method: "method", silent: true
91
+ end
92
+ assert_equal "/:id/show", first[:url]
93
+ assert_equal /^\/[[:graph:]]+\/show$/, first[:match]
16
94
  end
17
95
 
18
96
  end
data/version CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.1
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.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a