nephos-server 0.1.6 → 0.1.7

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: de5678099fcc3956f42a2a7514fa6b361150d534
4
- data.tar.gz: bd85f6a4f24f28e8187e2826891d35fc1a1f924e
3
+ metadata.gz: b13edc23b32693d79a6ff436f805f2ac7a57d941
4
+ data.tar.gz: a25a361fe88d7763e4f7aee48a92cea306855197
5
5
  SHA512:
6
- metadata.gz: b863db2c4a3f057ded010093ca174a065c036b78fb784523e294e8f117d94635e9b94339bdfeefe99f21f1b3ad5881b995266e96c3b72cf5e36f131db8ef4de4
7
- data.tar.gz: 1bb97559b4f080c79f1c877cce79583e9c5399b7e6415087c0ee92cf67a902226749cd96614436eb3e803e6fa6c4ba99057ca8ad0da87711bbc79b90a528aa18
6
+ metadata.gz: 66d81d163d29377255e3a5c866fdc4076e70e8d70d8276798152f03bee4900615b20010429c79831448c78597026ea5035bd1449babffeabebf517408881bff3
7
+ data.tar.gz: f63d4ede65f21ad854d88b5d4ff02d50552be506c3e347a087eafb09339dca12d40f87325b433fee0cb42aab7c0a27e5b57958ee5826bb603a8aae6f6376a0ff
data/bin/nephos-server CHANGED
@@ -31,6 +31,9 @@ begin
31
31
 
32
32
  Nephos::Server.start($server_port)
33
33
 
34
+ rescue RoutingError => err
35
+ puts "Routing Error. Check out the documentation and `routes.rb` file: #{err.message}"
36
+
34
37
  rescue => err
35
38
  puts "Error: #{err.message}"
36
39
  end
@@ -1,6 +1,8 @@
1
- class RoutingError < Exception; end
1
+ class RoutingError < StandardError; end
2
2
  class InvalidRoute < RoutingError; end
3
- class InvalidGetRoute < InvalidRoute; end
3
+ class InvalidRouteUrl < InvalidRoute; end
4
+ class InvalidRouteController < InvalidRoute; end
5
+ class InvalidRouteMethod < InvalidRoute; end
4
6
 
5
7
  module Nephos
6
8
  module Route
@@ -11,10 +13,20 @@ module Nephos
11
13
  end
12
14
 
13
15
  def self.check!(what)
14
- raise InvalidGetRoute if not what.keys.include? :url
15
- raise InvalidGetRoute if not what.keys.include? :controller
16
- raise InvalidGetRoute if not what.keys.include? :method
17
- # TODO: more check to do
16
+ raise InvalidRouteUrl, "Missing URL" unless what.keys.include? :url
17
+ raise InvalidRouteController, "Missing Controller" unless what.keys.include? :controller
18
+ raise InvalidRouteMethod, "Missing Method" unless what.keys.include? :method
19
+ begin
20
+ controller = Module.const_get(what[:controller])
21
+ rescue
22
+ raise InvalidRouteController, "Controller \"#{what[:controller]}\" doesn't exists"
23
+ end
24
+ if not controller.ancestors.include? Nephos::Controller
25
+ raise InvalidRouteController, "Class \"#{what[:controller]}\" is not a Nephos::Controller"
26
+ end
27
+ if not controller.new({}, {}).respond_to? what[:method]
28
+ raise InvalidRouteMethod, "No method named \"#{what[:method]}\""
29
+ end rescue raise InvalidRouteController, "Cannot initialize controller"
18
30
  end
19
31
 
20
32
  end
@@ -27,6 +39,7 @@ end
27
39
 
28
40
  # @params what [Hash]
29
41
  def get what
42
+ raise InvalidRoute unless what.is_a? Hash
30
43
  what[:url] = File.expand_path File.join(route_prefix, what[:url])
31
44
  Nephos::Route.check!(what)
32
45
  Nephos::Route.add(what, "GET")
@@ -34,6 +47,7 @@ end
34
47
 
35
48
  # @params what [Hash]
36
49
  def post what
50
+ raise InvalidRoute unless what.is_a? Hash
37
51
  what[:url] = File.join(route_prefix, what[:url])
38
52
  Nephos::Route.check!(what)
39
53
  Nephos::Route.add(what, "POST")
@@ -41,6 +55,7 @@ end
41
55
 
42
56
  # @params what [Hash]
43
57
  def put what
58
+ raise InvalidRoute unless what.is_a? Hash
44
59
  what[:url] = File.join(route_prefix, what[:url])
45
60
  Nephos::Route.check!(what)
46
61
  Nephos::Route.add(what, "PUT")
@@ -1 +1 @@
1
- class InvalidApplicationError < RuntimeError ; end
1
+ class InvalidApplicationError < RuntimeError; end
data/version CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
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.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a