nephos-server 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1203bd481ae96bab872a8b513b5ca43e4deb905c
4
- data.tar.gz: 34e8f81c66ba25156a0c060a2eb72ea0ce6de8e6
3
+ metadata.gz: a8b7fa251ffb5faae0d07c460068da7b1462c69f
4
+ data.tar.gz: 7ef60b41475e3763ac0b9cfc6c177d0556099ec7
5
5
  SHA512:
6
- metadata.gz: b29c622c41367e8988b7c39ac92957d097597f0a02d1d82194333a0ef73e3dabf60cc3b3a016fcbb89aaf66e7f1c6577dd5cbe0cd088db7fe649d9be184b55cf
7
- data.tar.gz: 60652986c5c4f8227298e1e48531318f0b648415fd247ff7cc8523b364785ec0780ea5c5d93863617144d7770ffb44f041671f4593cd78b1318aaf63f95808e4
6
+ metadata.gz: ab7e88e906675e7f39d5f736cf554719caaaf97eb5f6269b098b6371ac7f0fcdb3d7f9d8e7473325e8d412aa980b9c229e5dc3412c3ff9b5fe1f150274083020
7
+ data.tar.gz: e7002eca788be88b22dd135506afad8cc14b76775c33e323ea170c1d33c0d6305a9f5de1a0731afeb82ae7393afb3bc333073bebf421d7666b887ab1f510001e
data/README.md CHANGED
@@ -41,7 +41,11 @@ The basic code of a controller can be generated via ``nephos-generator controlle
41
41
  ```ruby
42
42
  class Example < Nephos::Controller
43
43
  def root
44
- return {plain: "index"}
44
+ if params["index"] == "true"
45
+ return {plain: "index"}
46
+ else
47
+ return :empty
48
+ end
45
49
  end
46
50
  end
47
51
  ```
data/lib/nephos-server.rb CHANGED
@@ -7,4 +7,6 @@ require 'rack'
7
7
  require 'colorize'
8
8
 
9
9
  require_relative 'nephos-server/basic_errors'
10
+ require_relative 'nephos-server/params'
11
+ require_relative 'nephos-server/controller'
10
12
  require_relative 'nephos-server/server/main'
@@ -7,3 +7,6 @@ class InvalidRouteMethod < InvalidRoute; end
7
7
  class InvalidApplication < RuntimeError; end
8
8
  class InvalidGit < InvalidApplication; end
9
9
  class NoGitBinary < InvalidGit; end
10
+
11
+ class ParsingError < StandardError; end
12
+ class MissingKey < ParsingError; end
@@ -0,0 +1,29 @@
1
+ module Nephos
2
+ class Controller
3
+
4
+ attr_reader :env, :infos, :callpath
5
+
6
+ # @param env [Hash] env extracted from the http request
7
+ # @param parsed [Hash] pre-parsed env with parameters, ...
8
+ def initialize env={}, parsed={path: [], args: {}}, callpath={params: []}
9
+ raise ArgumentError, "env must be a Hash" unless env.is_a? Hash
10
+ raise ArgumentError, "parsed must be a Hash" unless parsed.is_a? Hash
11
+ raise ArgumentError, "callpath must be a Hash" unless callpath.is_a? Hash
12
+ raise ArgumentError, "Invalid Parsed. :path must be associated with an Array" unless parsed[:path].is_a? Array
13
+ raise ArgumentError, "Invalid Parsed. :args must be associated with a Hash" unless parsed[:args].is_a? Hash
14
+ raise ArgumentError, "Invalid Callpath. :params must be associated with an Array" unless callpath[:params].is_a? Array
15
+ @env= env
16
+ @infos= parsed
17
+ @callpath= callpath
18
+ @params= parsed[:args]
19
+ @params.merge! Params.new(Hash[callpath[:params].zip @infos[:path]])
20
+ @params.select!{|k,v|k}
21
+ end
22
+
23
+ def arguments
24
+ @params
25
+ end
26
+ alias :params :arguments
27
+
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ module Nephos
4
+ class Params
5
+
6
+ def initialize(hash={})
7
+ raise ArgumentError, "the first argument must be a Hash" unless hash.is_a? Hash
8
+ @hash = Hash[hash.map{|k,v| [k.to_s, v]}]
9
+ end
10
+
11
+ def method_missing m, *a
12
+ @hash.send(m, *(a.map(&:to_s)))
13
+ @hash.send(m, *a)
14
+ end
15
+
16
+ def [] i
17
+ @hash[i.to_s]
18
+ end
19
+
20
+ def []= i, v
21
+ @hash[i.to_s] = v.to_s
22
+ end
23
+
24
+ end
25
+ end
@@ -1,5 +1,3 @@
1
- require_relative 'controller'
2
-
3
1
  Dir[File.expand_path "controllers/*.rb"].each do |f|
4
2
  load(f) and puts "#{f} loaded"
5
3
  end
@@ -27,7 +27,7 @@ module Nephos
27
27
  def self.check_controller! what
28
28
  begin
29
29
  controller = Module.const_get(what[:controller])
30
- rescue
30
+ rescue => err
31
31
  raise InvalidRouteController, "Controller \"#{what[:controller]}\" doesn't exists"
32
32
  end
33
33
  if not controller.ancestors.include? Nephos::Controller
@@ -35,7 +35,7 @@ module Nephos
35
35
  end
36
36
  begin
37
37
  instance = controller.new
38
- rescue
38
+ rescue => err
39
39
  raise InvalidRouteController, "Cannot initialize controller"
40
40
  end
41
41
  return instance
@@ -11,11 +11,12 @@ Gem::Specification.new do |s|
11
11
  s.files = %w(
12
12
  lib/nephos-server.rb
13
13
  lib/nephos-server/basic_errors.rb
14
+ lib/nephos-server/params.rb
15
+ lib/nephos-server/controller.rb
14
16
  lib/nephos-server/server/main.rb
15
17
  lib/nephos-server/server/responder.rb
16
18
  lib/nephos-server/routing/execute.rb
17
19
  lib/nephos-server/routing/load.rb
18
- lib/nephos-server/routing/controller.rb
19
20
  README.md
20
21
  Rakefile
21
22
  Procfile
@@ -26,6 +27,8 @@ version
26
27
  test/test.rb
27
28
  test/responder.rb
28
29
  test/routing.rb
30
+ test/params.rb
31
+ test/controller.rb
29
32
  routes.rb
30
33
  controllers/dataset.rb
31
34
  controllers/image.jpg
@@ -0,0 +1,9 @@
1
+ class TestNephosServerController < Test::Unit::TestCase
2
+
3
+ def test_initialize
4
+ assert Nephos::Controller.new()
5
+ assert Nephos::Controller.new(env={}, {path: [], args: {}}, {params: []})
6
+ assert_raise do Nephos::Controller.new({}, {}, {}) end
7
+ end
8
+
9
+ end
data/test/params.rb ADDED
@@ -0,0 +1,14 @@
1
+ class TestNephosServerParams < Test::Unit::TestCase
2
+
3
+ def test_basic
4
+ p = Nephos::Params.new
5
+ assert p.empty?
6
+ p[:a] = "1"
7
+ assert_equal p[:a], "1"
8
+ assert_equal p["a"], "1"
9
+ p["a"] = "2"
10
+ assert_equal p[:a], "2"
11
+ assert_equal p["a"], "2"
12
+ end
13
+
14
+ end
data/test/responder.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  class TestNephosServerResponder < Test::Unit::TestCase
3
2
 
4
3
  def test_content_type
data/test/test.rb CHANGED
@@ -6,3 +6,5 @@ end
6
6
 
7
7
  require_relative 'responder'
8
8
  require_relative 'routing'
9
+ require_relative 'controller'
10
+ require_relative 'params'
data/version CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
@@ -58,11 +58,12 @@ email:
58
58
  - poulet_a@epitech.eu
59
59
  - - lib/nephos-server.rb
60
60
  - lib/nephos-server/basic_errors.rb
61
+ - lib/nephos-server/params.rb
62
+ - lib/nephos-server/controller.rb
61
63
  - lib/nephos-server/server/main.rb
62
64
  - lib/nephos-server/server/responder.rb
63
65
  - lib/nephos-server/routing/execute.rb
64
66
  - lib/nephos-server/routing/load.rb
65
- - lib/nephos-server/routing/controller.rb
66
67
  - README.md
67
68
  - Rakefile
68
69
  - Procfile
@@ -73,6 +74,8 @@ email:
73
74
  - test/test.rb
74
75
  - test/responder.rb
75
76
  - test/routing.rb
77
+ - test/params.rb
78
+ - test/controller.rb
76
79
  - routes.rb
77
80
  - controllers/dataset.rb
78
81
  - controllers/image.jpg
@@ -97,13 +100,16 @@ files:
97
100
  - controllers/main.rb
98
101
  - lib/nephos-server.rb
99
102
  - lib/nephos-server/basic_errors.rb
100
- - lib/nephos-server/routing/controller.rb
103
+ - lib/nephos-server/controller.rb
104
+ - lib/nephos-server/params.rb
101
105
  - lib/nephos-server/routing/execute.rb
102
106
  - lib/nephos-server/routing/load.rb
103
107
  - lib/nephos-server/server/main.rb
104
108
  - lib/nephos-server/server/responder.rb
105
109
  - nephos-server.gemspec
106
110
  - routes.rb
111
+ - test/controller.rb
112
+ - test/params.rb
107
113
  - test/responder.rb
108
114
  - test/routing.rb
109
115
  - test/test.rb
@@ -1,23 +0,0 @@
1
- module Nephos
2
- class Controller
3
-
4
- attr_reader :env, :infos, :callpath
5
-
6
- # @param env [Hash] env extracted from the http request
7
- # @param parsed [Hash] pre-parsed env with parameters, ...
8
- def initialize env={}, parsed={path: [], args: {}}, callpath={params: []}
9
- @env= env
10
- @infos= parsed
11
- @callpath= callpath
12
- @params= parsed[:args]
13
- @params.merge! Hash[callpath[:params].zip @infos[:path]]
14
- @params.select!{|k,v|k}
15
- end
16
-
17
- def arguments
18
- @params
19
- end
20
- alias :params :arguments
21
-
22
- end
23
- end