rackr 0.0.4 → 0.0.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rackr/router/errors.rb +51 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdefbf566acec64232a4dc955298b3790f174884219515361cc41392191182ba
4
- data.tar.gz: 06552a5aa5dae83ce342c31df357a1e805150ecd31cbb356f76281cecec73617
3
+ metadata.gz: 8c92b9939e63fb6f89dde70e441527279567e58ee6a9a2a490d195b093e083e0
4
+ data.tar.gz: c9f0f1ab708b742d319de83e314b2f37dbe6ab0eafa85496cb3ff2ac8f333466
5
5
  SHA512:
6
- metadata.gz: 926c42e1321efc1bb16fb1b8a7b40ddb81e59c57f6f79174ed619ed8aed6ca788523cc3ad6f7224ca2c78c99b1e174cd4617929a8836fa1678bde0504445ea0c
7
- data.tar.gz: 8d10b27258450d640dfd413554dd4dd4cc0e3cc153992929f89c96265df2005b6d7d46ce4a86549e46814499de740011d3d74442ce78fbd9e932ade9361f4e49
6
+ metadata.gz: b637fb24fc243de2461370122a0228e6228537f62ce658fbaddeb12a9d30974795d33adf48029a380e4ed26fadcc8c05f4b60a6f59e855c32452af2bcf23ac3a
7
+ data.tar.gz: c3e7397002bf65a165459ebcae8cc5d5976843b009f88d20e6596fa0787408ff18391de071e2d538323f92cd505478fdba37e4536e0cecb4abf48550859b70a9
@@ -0,0 +1,51 @@
1
+ class Rackr
2
+ class Router
3
+ module Errors
4
+ class Error < StandardError; end
5
+ class InvalidNamedRouteError < Error; end
6
+ class UndefinedNamedRouteError < Error; end
7
+ class InvalidEndpointError < Error; end
8
+ class InvalidCallbackError < Error; end
9
+ class InvalidPathError < Error; end
10
+ class InvalidBranchNameError < Error; end
11
+
12
+ class << self
13
+ def check_branch_name(path)
14
+ return if path.is_a?(String) || path.is_a?(Symbol)
15
+
16
+ raise(InvalidBranchNameError, "Route branch name must be a `string` or a `symbol`, got: '#{path}'")
17
+ end
18
+
19
+ def check_path(path)
20
+ return if path.is_a?(String) || path.is_a?(Symbol) || path.nil?
21
+
22
+ raise(InvalidPathError, "Path must be a `string`, `symbol` or `nil`, got: '#{path}'")
23
+ end
24
+
25
+ def check_as(as, path)
26
+ return if as.is_a?(String) || as.is_a?(Symbol) || as.nil?
27
+
28
+ raise(InvalidNamedRouteError, "as: argument in routes and branches must be a `string` or a `symbol`, got: '#{as}' for '#{path}'")
29
+ end
30
+
31
+ def check_callbacks(callbacks, path)
32
+ check = lambda { |callback|
33
+ unless callback.nil? || callback.respond_to?(:call) || (callback.respond_to?(:new) && callback.instance_methods.include?(:call))
34
+ raise(InvalidCallbackError, "Callbacks must respond to a `call` method or be a class with a `call` instance method, got: '#{callback.inspect}' for '#{path}'")
35
+ end
36
+ }
37
+
38
+ callbacks.is_a?(Array) ? callbacks.compact.each(&check) : check.call(callbacks)
39
+ end
40
+
41
+ def check_endpoint(endpoint, path)
42
+ if endpoint.respond_to?(:call) || (endpoint.respond_to?(:new) && endpoint.instance_methods.include?(:call))
43
+ return
44
+ end
45
+
46
+ raise(InvalidEndpointError, "Endpoints must respond to a `call` method or be a class with a `call` instance method, got: '#{endpoint.inspect}' for '#{path}'")
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
@@ -69,6 +69,7 @@ files:
69
69
  - lib/rackr/callback.rb
70
70
  - lib/rackr/router.rb
71
71
  - lib/rackr/router/build_request.rb
72
+ - lib/rackr/router/errors.rb
72
73
  - lib/rackr/router/route.rb
73
74
  homepage: https://github.com/henrique-ft/rackr
74
75
  licenses: