nephos-server 0.6.3 → 0.6.4

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: fd4f2176f42e827ebb36ac19f651e3adb12e7609
4
- data.tar.gz: 99677cc04947d8c967c358d8e2cc8dab847e5879
3
+ metadata.gz: a7a62dad08b09b531aab62f3e9800f65ec7e849d
4
+ data.tar.gz: ffd36f823891ca5141950551e6e3de7984f8b8d4
5
5
  SHA512:
6
- metadata.gz: 4d609afb7b502b5ab9831f289b0029cecfbe0ea3ccf8c8c86686df86e575eb1021a8b73b7f39fc4449ce00cecd0c018b264f322d5cfcbce8977345bc65e67824
7
- data.tar.gz: 1db01ad58ca2bec79883ca541b8e6d6bd436fea5622b4f0fe193fdcecc1864a917ea3595fe7c8347d0678be3d5d30e4168f5d462ecfdbda00f85886f78b3f291
6
+ metadata.gz: 58a3d571167c75ccd6ebc97bc56fd4ec44c766b1dccfe3748746b467e44db39d3fe3ea3cd8588fdb3b53f92f692f0fd5b28fafe87537e4e4b7910637a84e90df
7
+ data.tar.gz: bbf86241ed2a7671d81b84cdea1c32960ef0e698ff29a0b37c246a2f7d0940b0d12ad13f14f5d1a7d606a53c55da93b44bf85ed6f9bb5a52ea0b7235c2882540
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,4 @@
1
+ ��β�G����Г ��kp-Ĥ�V�v�`'#�%��?�{��yjq���7��-��A�\,wX`6a���jV?Vt7vk1a`{����X����X�7�
2
+ G��0��S�� ��c���O 1����Ţ:�ɵ�uUD#�)�;m�m����@��%D�wO��m�*���퉊�1j�۽<�J'��R
3
+ Z`�ɀ����۶B��#�Ln�ÒrRK�jzl
4
+ ��<��������a&�(M�-�FS����)I�� 9�r�
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.6.4
2
+ * Fix application generator (replace in the gemfile nephos-server by nephos)
3
+ * Improve guides (more doc, corrections, update)
4
+ * Certificate for sign the gem
5
+
1
6
  v0.6.3
2
7
  * Add customisable default error page
3
8
 
@@ -1,7 +1,6 @@
1
1
  # Render API
2
2
 
3
3
  ## Understand the API
4
-
5
4
  The render API is a simple system to allows you to render HTTP responses to a client.
6
5
  The API allows you to customize differents parts of the response:
7
6
 
@@ -13,22 +12,21 @@ The API use the returns of the Controllers methods to build the HTTP responses.
13
12
 
14
13
 
15
14
  ## Use the API
16
-
17
15
  To use the API, you have to create a new controller.
18
- The controller must be placed or requires in the ``app/`` directory,
19
- via a ``file.rb`` file.
20
- It must contain a class, wich inherit from ``Nephos::Controller``.
21
- Each public method can be an entry point, defined in the ``routes.rb`` file.
22
- [Routing doc](GUIDE_ROUTING.md).
16
+ The controller must be placed or requires in the ``app/`` directory. Check the
17
+ [Guide about the controller](GUIDE_CONTROLLER.md).
18
+
19
+ It must contain a class, inheriting from ``Nephos::Controller``.
20
+ Each public method **can** be an entry point, defined in the ``routes.rb`` file.
21
+ [Routing documentation](GUIDE_ROUTING.md).
23
22
 
24
23
  In the controller, you can use few helpers,
25
- like the method ``params()``, ``env()``, and ``infos()``
24
+ like the method ``params()`` and ``cookies``
26
25
 
27
26
  The methods used as entry point must return a ``Hash`` described in the following lines.
28
27
  It may optionnaly be an ``Integer``, to return only a status, or ``:empty``.
29
28
 
30
29
  ## Options
31
-
32
30
  The returns of a Controller method can include the following keys:
33
31
 
34
32
  - :plain
@@ -57,14 +55,12 @@ end
57
55
  The following sections will describe how each key works and modify the HTTP response.
58
56
 
59
57
  ### Content
60
-
61
58
  The ``:content`` key must be associated with a ``String`` (or ``Hash`` is json).
62
59
 
63
60
  **Optionnal**:
64
61
  a default value is provided, based on the ``:status`` if no ``:content`` if specified.
65
62
 
66
63
  ### Type
67
-
68
64
  The ``:type`` key has to be associated with a ``String`` matching with **"kind/type"**.
69
65
 
70
66
  **Optionnal**:
@@ -74,13 +70,11 @@ Kinds and Types (called type and sub-type by w3c) are described here:
74
70
  [the w3c documentation](http://www.w3.org/Protocols/rfc1341/4_Content-Type.html)
75
71
 
76
72
  #### Kind:
77
-
78
73
  - image
79
74
  - text
80
75
  - ...
81
76
 
82
77
  #### Type:
83
-
84
78
  - plain
85
79
  - javascript
86
80
  - jpeg
@@ -88,7 +82,6 @@ Kinds and Types (called type and sub-type by w3c) are described here:
88
82
 
89
83
 
90
84
  ### Status
91
-
92
85
  The ``:status`` key is associable with an Integer. It must represent the HTTP status code.
93
86
 
94
87
  **Optionnal**:
@@ -98,7 +91,6 @@ The default value is 200.
98
91
 
99
92
 
100
93
  ### Plain, HTML, JSON
101
-
102
94
  The keys ``:plain``, ``:html``, ``:json`` can replace both ``:content`` ``:type``.
103
95
  It is associated like ``:content`` and **replace automaticaly the type**.
104
96
 
@@ -3,5 +3,69 @@
3
3
  ## Intern architecture
4
4
 
5
5
  ### Cookies
6
+ You can set cookies and get them via ``cookies`` in the body of any controller.
6
7
 
7
- You can set cookies and get them via ``cookies`` in the body of the controller.
8
+ ### Params
9
+ You can access to the parameters (defined by http or via the URI, based on your
10
+ routing rules).
11
+ They are accessible via ``params`` in the body of every controller.
12
+
13
+ ### Hooks
14
+ You can define hooks, which are some methods, called every times, before or
15
+ after a call to a routed method. There is 2 kinds of hook actually:
16
+
17
+ - after_action
18
+ - before_action
19
+
20
+ Each of them will be called juste before or after calling the method requested.
21
+ It means that the cookies are not saved yet (so you can change them, etc.)
22
+
23
+ The hooks are defined by calling the methods ``after_action`` or
24
+ ``before_action``, out of a method, usually on the top of the controller.
25
+
26
+ Hooks take 1 or 2 arguments.
27
+ - The first is the name of the method to call.
28
+ - The second, **optional**, is a hash, containing ``:only`` or ``:except``
29
+ keys, associated to an Array or Symbol or one Symbol. Each symbol represents
30
+ a method triggering the hook.
31
+
32
+ **Note: If there is no 2sd argument, then the hook is triggered every times.**
33
+
34
+ **Note: except is not already implemented**
35
+
36
+ Example:
37
+ ```ruby
38
+ class MainController < Nephos::Controller
39
+
40
+ before_action :fct_before_all
41
+ before_action :fct_before_root, only: [:root]
42
+ after_action :fct_after_root, only: :root
43
+
44
+ def fct_before_all
45
+ # puts "BEFORE ALL"
46
+ end
47
+
48
+ def fct_before_root
49
+ # puts "BEFORE"
50
+ end
51
+
52
+ def fct_after_root
53
+ # puts "AFTER"
54
+ end
55
+
56
+ def root
57
+ # puts "ROOT"
58
+ cookies["a"] = "b"
59
+ cookies.delete("b").to_h
60
+ # puts "Cookies from the root:", cookies
61
+ {
62
+ json: {
63
+ list: $dataset,
64
+ add: '/add',
65
+ rm: '/rm',
66
+ }
67
+ }
68
+ end
69
+
70
+ end
71
+ ```
@@ -1,25 +1,30 @@
1
1
  # Routing Guide
2
2
 
3
- ## How the routes are inputed by the client ?
4
-
3
+ ### How the routes are inputed by the client ?
5
4
  Each HTTP request made by the client will contains a **REQUEST_URI** value.
6
5
  The web server receive this information, and will choose what to do,
7
6
  based on the rules you will define.
8
7
 
9
- ## How to define the rules ?
10
-
11
- You have to write the rules in the ``/routes.rb`` file.
8
+ ### How to define the rules ?
9
+ The rules definitions are writen in the ``/routes.rb`` file.
12
10
  Few helpers are provided to make the job easier.
13
- They will be described in the following section.
11
+ They will be described in the section ([helpers](#the-helpers)).
12
+
13
+ ### Is there default rules ?
14
+ No there is not, but, there is still 2 kind of response that you cannot route:
15
+
16
+ 1. If you did not write the route requested, then it will be a 404 error.
17
+ 2. If the controller contains errors (not a valid return, or uncaught exception), then a 505 is returned.
18
+
19
+ To handle these errors, your should see [error guide](GUIDE_ERRORS.md).
14
20
 
15
- ## The helpers
16
21
 
22
+ ## The helpers
17
23
  As every HTTP request requires an HTTP verb, there is 4 helpers to handle them.
18
24
  ``get``, ``post``, ``put``, ``add_route``. Indeed, there is 3 main verbs (GET POST PUT).
19
25
  But as you can need to create other verbs (DELETE, PATCH, ...), we allows you to handle them.
20
26
 
21
27
  ### add_route
22
-
23
28
  The method ``add_route`` take 2 arguments.
24
29
 
25
30
  1. verb (has to be a string, upcase as possible, like **GET**)
@@ -32,39 +37,54 @@ The option argument must contains the 3 following keys:
32
37
  - ``:method``: the method of the controller that will be used to compute and render a result to the client.
33
38
 
34
39
  As example, yuo can write:
35
-
36
40
  ```ruby
37
41
  add_route "GET", url: "/tmp", controller: "MyController", method: "tmp"
38
42
  ```
39
43
 
40
44
  ### get post put
41
-
42
45
  Theses 3 helpers allows you to use ``add_route`` without the first argument.
43
46
 
47
+ Example:
48
+ ```ruby
49
+ get url: "/tmp", controller: "MyController", method: "tmp"
50
+ post url: "/tmp", controller: "MyController", method: "tmp"
51
+ ```
44
52
  ### resource
45
-
46
53
  This method takes 1 parameter and 1 block.
47
54
  The parameter is a partial url, and the bloc, other routes.
48
55
 
49
56
  Resource can be chained many times.
50
- For Example, you can do this:
51
57
 
58
+ For example, you can do this:
52
59
  ```ruby
53
60
  resource "user" do
61
+ get url: "/index", controller: "UserController", method: "show" # /user/index
54
62
  resource "informations" do
55
- get url: "/index", controller: "UserController", method: "show" # /user/informations/index
63
+ get url: "/", controller: "UserController", method: "show" # /user/informations/
56
64
  end
57
65
  end
58
66
  ```
59
67
 
60
- It will generate the route ``/home/index``, calling the ``MainController#root`` method.
61
-
62
-
63
68
  ## URL Parameters
69
+ The parameters can be passed through the URL. To allow a resource to have
70
+ parameters, you will have to place a ``/:param`` in your route rules. The
71
+ parameter will be placed in the controller in the ``params`` method, an be
72
+ accessible via ``params[:param]``. This is the reason why you should never
73
+ have 2 URL parameters with the same name, because only the last will be usable.
64
74
 
65
- **TODO: more documentation**
66
-
67
- place a ``/:param`` in your route. The parameter will be placed in the controller in the ``params`` method
75
+ Example:
76
+ ```ruby
77
+ resource "user" do
78
+ get url: "/:id", controller: "UserController", method: "show" # /user/(anything)
79
+ end
80
+ resource "static" do
81
+ resource ":page" do
82
+ get url: "/", controller: "StaticPageController", method: "show" # /static/(anything)
83
+ get url: "/edit", controller: "StaticPageController", method: "edit" # /static/(anything)/edit
84
+ put url: "/", controller: "StaticPageController", method: "update" # /static/(anything)
85
+ end
86
+ end
87
+ ```
68
88
 
69
89
  ## Notes
70
90
 
data/README.md CHANGED
@@ -19,7 +19,6 @@ Features which will not be provided by nserver:
19
19
  - [Sequel](DOCUMENTATION/DATABASE/SEQUEL.md)
20
20
 
21
21
  # Start
22
-
23
22
  ```sh
24
23
  gem install nephos # download the server and executables
25
24
  ngenerator application MyApp # generate the application
@@ -39,7 +38,6 @@ nserver -p 8080 -h 0.0.0.0 # start the server. port is not required, neither hos
39
38
  # Documentation
40
39
 
41
40
  ## Guides
42
-
43
41
  Theses guides will provide you knowlegde about everything you can use in the application.
44
42
 
45
43
  - [Generator GUIDE](DOCUMENTATION/GUIDE_GENERATOR.md)
@@ -51,16 +49,16 @@ Theses guides will provide you knowlegde about everything you can use in the app
51
49
 
52
50
  ## Examples
53
51
 
54
- ### Production
55
-
56
- To avoid information leaks from your application, set the environment variable ``export ENVIRONMENT=production``,
57
- or run the server with ``-e production`` parameter.
58
- It will disable ruby error messages when an error occurs in the controller.
52
+ ### Production and environment
53
+ To avoid information leaks from your application, set the environment variable
54
+ ``export ENVIRONMENT=production``, or run the server with ``-e production``
55
+ parameter. When an error occurs, the backtrace will be print to the client in
56
+ the rendered page, unless the server runs in production environment.
59
57
 
60
58
  ### Controller
61
-
59
+ Every routes will call a method from a controller.
62
60
  To create a controller, add a ruby file to ``app/``, with a class inherited by ``Nephos::Controller``
63
- The basic code of a controller can be generated via ``ngenerator controller NAME``.
61
+ You should user ``ngenerator --controller NAME`` to generate a new controller.
64
62
 
65
63
  ```ruby
66
64
  class Example < Nephos::Controller
@@ -76,7 +74,6 @@ end
76
74
  ```
77
75
 
78
76
  ### Rendering
79
-
80
77
  To render a content to the client, you can return informations from a Controller method:
81
78
 
82
79
  ```ruby
@@ -91,7 +88,6 @@ return :empty
91
88
  ```
92
89
 
93
90
  ### Routing
94
-
95
91
  The routing (rules to execute the action the user wants), you have to write the ``/routes.rb`` file.
96
92
  If the user try to access an url not described in the file, it will automaticaly render a 404 not found.
97
93
 
@@ -111,13 +107,14 @@ end
111
107
  # Developers: Roadmap
112
108
 
113
109
  ## TODO v0.6
114
- - feature to change HTTP header from controller
110
+ - Alias for routing
115
111
  - functionnal tests
112
+ - extension for urls (optional .xxx, with controller effect)
116
113
 
117
114
  ## TODO v0.7
115
+ - feature to change HTTP header from controller
118
116
  - Documentation on architecture (UML)
119
117
  - Improved documentation (Tutorial, Improved guides)
120
- - Alias for routing
121
118
 
122
119
  ## v1 requierements
123
120
  - Environement, Daemons, Port, Listen Host, Routables, Arguments
data/app/image.jpg CHANGED
Binary file
data/bin/nephos-generator CHANGED
@@ -9,7 +9,7 @@ require_relative '../lib/nephos-server/bin-helpers'
9
9
  GEMFILE = <<EOF
10
10
  source 'https://rubygems.org'
11
11
 
12
- gem 'nephos-server'
12
+ gem 'nephos'
13
13
  EOF
14
14
 
15
15
  ROUTE_RB = <<EOF
@@ -73,7 +73,7 @@ module Nephos
73
73
  rescue => err
74
74
  STDERR.puts "Error: #{err.message}"
75
75
  STDERR.puts err.backtrace
76
- return error_custom(req, 500, "Error: 500\n#{err.message}\n---Backtrace---\n#{err.backtrace.join("\n")}\n")
76
+ return error_custom(req, 500, "#{err.message}\n---Backtrace---\n#{err.backtrace.join("\n")}\n")
77
77
  end
78
78
  end
79
79
 
@@ -60,8 +60,9 @@ nephos-status
60
60
  )
61
61
  s.homepage = 'https://github.com/pouleta/NephosRubyServer'
62
62
  s.license = 'GNU/GPLv3'
63
- #s.cert_chain = ['certs/poulet_a.pem']
64
- #s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
63
+
64
+ s.cert_chain = ['certs/nephos.pem']
65
+ s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
65
66
 
66
67
  # s.add_dependency 'nephos', '~> 1.0'
67
68
  s.add_dependency 'nomorebeer', '~> 1.1'
@@ -9,7 +9,23 @@ class TestNephosServerGenerator < Test::Unit::TestCase
9
9
  assert(File.exists? "/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
- assert(gemfile_data.include? "gem 'nephos-server'")
12
+ assert(gemfile_data.include? "gem 'nephos'")
13
+ `rm -rf /tmp/nephos-server-test 2> /tmp/null`
14
+ end
15
+
16
+ def test_generator_application_with_build
17
+ `rm -rf /tmp/nephos-server-test 2> /tmp/null`
18
+
19
+ `./bin/nephos-generator --test -a /tmp/nephos-server-test --no-git`
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")
23
+ assert(Dir.exists? "/tmp/nephos-server-test/app")
24
+ gemfile_data = File.read("/tmp/nephos-server-test/Gemfile").split("\n")
25
+ assert(gemfile_data.include? "gem 'nephos'")
26
+ gemfile_lock_data = File.read("/tmp/nephos-server-test/Gemfile.lock").split
27
+ assert(gemfile_lock_data.include? "nephos")
28
+ assert(gemfile_lock_data.include? "nephos-server")
13
29
  `rm -rf /tmp/nephos-server-test 2> /tmp/null`
14
30
  end
15
31
 
data/version CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.6.4
metadata CHANGED
@@ -1,14 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephos-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRYwFAYDVQQDDA1hcnRo
14
+ dXIucG91bGV0MRkwFwYKCZImiZPyLGQBGRYJY3J5cHRvbGFiMRMwEQYKCZImiZPy
15
+ LGQBGRYDbmV0MB4XDTE1MTAwMzIxNTQyMFoXD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
31
+ tcYkgfqUJPitIJx1RvWZpIyH5uJhRUYK3+vU9nMOxez5WbIlC1TtpByKAPMX+sht
32
+ gib3AoIT8jh/2w==
33
+ -----END CERTIFICATE-----
34
+ date: 2015-10-03 00:00:00.000000000 Z
12
35
  dependencies:
13
36
  - !ruby/object:Gem::Dependency
14
37
  name: nomorebeer
@@ -141,7 +164,6 @@ rubyforge_project:
141
164
  rubygems_version: 2.4.8
142
165
  signing_key:
143
166
  specification_version: 4
144
- summary: "* Improve daemons * Improve Rakefile and tests structure * Add few functional
145
- (router, server, generator) tests * Add new unitary tests"
167
+ summary: "* Fix application generator (replace in the gemfile nephos-server by nephos)"
146
168
  test_files: []
147
169
  has_rdoc:
metadata.gz.sig ADDED
Binary file