sansom 0.1.0 → 0.1.1
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 +4 -4
- data/changelog.md +6 -1
- data/lib/sansom.rb +39 -27
- data/sansom.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaef12414047fe120425a2b7d60774ff95bb7e6f
|
4
|
+
data.tar.gz: fa9631815362d92010c669d521334aba3b7dacbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb88783579d57e97451d616a5dc974fd1a1d6cfd90d03b82000b65aa3bea44ddd60e17dae4f3f29f2ffbd531784569409fcff1b467e57311170d1ffbceb098f9
|
7
|
+
data.tar.gz: 299ac437e310dd9fa8355923bfcfdc4aa84dd5f7c295be28e482e86bab88dac728fd575cde02b825f4321718a679e74d8d3f4f82b83f12df206446280131665b
|
data/changelog.md
CHANGED
@@ -52,4 +52,9 @@ Here's an example
|
|
52
52
|
|
53
53
|
- PUBLIC RELEASE!
|
54
54
|
- After block added
|
55
|
-
- Improved routing behavior & speed
|
55
|
+
- Improved routing behavior & speed
|
56
|
+
|
57
|
+
0.1.1
|
58
|
+
|
59
|
+
- Fix bad bug in method_missing
|
60
|
+
- Added better error handling (per-error handling and a generic block that gets called if no specific handler is present)
|
data/lib/sansom.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative "./rack/fastlint.rb"
|
|
7
7
|
module Sansomable
|
8
8
|
InvalidRouteError = Class.new StandardError
|
9
9
|
HTTP_VERBS = [:get,:head, :post, :put, :delete, :patch, :options, :link, :unlink, :trace].freeze
|
10
|
+
ROUTE_METHODS = HTTP_VERBS+[:map]
|
10
11
|
RACK_HANDLERS = ["puma", "unicorn", "thin", "webrick"].freeze
|
11
12
|
NOT_FOUND = [404, {}, ["Not found."]].freeze
|
12
13
|
|
@@ -20,40 +21,46 @@ module Sansomable
|
|
20
21
|
|
21
22
|
def call env
|
22
23
|
return NOT_FOUND if tree.leaf? && tree.root?
|
23
|
-
|
24
|
+
|
24
25
|
r = Rack::Request.new env
|
25
26
|
m = tree.match r.path_info, r.request_method
|
26
|
-
|
27
|
+
|
27
28
|
return NOT_FOUND if m.nil?
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
begin
|
31
|
+
if @before_block && @before_block.arity == 1
|
32
|
+
bres = @before_block.call r
|
33
|
+
return bres if Rack::Fastlint.response bres
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
if m.url_params.count > 0
|
37
|
+
q = r.params.merge m.url_params
|
38
|
+
s = q.map { |p| p.join '=' }.join '&'
|
39
|
+
r.env["rack.request.query_hash"] = q
|
40
|
+
r.env["rack.request.query_string"] = s
|
41
|
+
r.env["QUERY_STRING"] = s
|
42
|
+
r.instance_variable_set "@params", r.POST.merge(q)
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
case m.item
|
46
|
+
when Proc then res = m.item.call r
|
47
|
+
else
|
48
|
+
raise InvalidRouteError, "Route handlers must be blocks or valid rack apps." unless m.item.respond_to? :call
|
49
|
+
r.env["PATH_INFO"] = m.remaining_path
|
50
|
+
res = m.item.call r.env
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
if @after_block && @after_block.arity == 2
|
54
|
+
ares = @after_block.call r, res
|
55
|
+
return ares if Rack::Fastlint.response ares
|
56
|
+
end
|
55
57
|
|
56
|
-
|
58
|
+
res
|
59
|
+
rescue StandardError => e
|
60
|
+
b = (@error_blocks[e.class] || @error_blocks[:default]) rescue nil
|
61
|
+
raise e if b.nil?
|
62
|
+
b.call e, r
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
def start port=3001
|
@@ -61,6 +68,11 @@ module Sansomable
|
|
61
68
|
Rack::Handler.pick(RACK_HANDLERS).run self, :Port => port
|
62
69
|
end
|
63
70
|
|
71
|
+
def error error_key=:default, &block
|
72
|
+
@error_blocks ||= {}
|
73
|
+
@error_blocks[error_key] = block
|
74
|
+
end
|
75
|
+
|
64
76
|
def before &block
|
65
77
|
@before_block = block
|
66
78
|
end
|
@@ -73,7 +85,7 @@ module Sansomable
|
|
73
85
|
path, item = *args.dup.push(block)
|
74
86
|
return super unless path && item
|
75
87
|
return super unless item != self
|
76
|
-
return super unless
|
88
|
+
return super unless ROUTE_METHODS.include? meth
|
77
89
|
tree.map_path path, item, meth
|
78
90
|
end
|
79
91
|
end
|
data/sansom.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "sansom"
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.1"
|
8
8
|
s.authors = ["Nathaniel Symer"]
|
9
9
|
s.email = ["nate@natesymer.com"]
|
10
10
|
s.summary = "Scientific, philosophical, abstract web 'picowork' named after Sansom street in Philly, near where it was made."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sansom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Symer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|