angelo 0.3.3 → 0.4.0

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.
@@ -1,98 +0,0 @@
1
- require 'mustermann'
2
-
3
- module Angelo
4
-
5
- module Mustermann
6
-
7
- # hrm, sneaky
8
- #
9
- def self.included base
10
- base.extend ClassMethods
11
- base.class_eval do
12
- def_delegator :@responder, :mustermann
13
- end
14
-
15
- [Responder, Responder::Websocket, Responder::Eventsource].each do |res|
16
- res.class_eval do
17
- attr_accessor :mustermann
18
- end
19
- end
20
- end
21
-
22
- module ClassMethods
23
-
24
- HTTPABLE.each do |m|
25
- define_method m do |path, opts = {}, &block|
26
- path = ::Mustermann.new path, opts
27
- routes[m][path] = Responder.new &block
28
- end
29
- end
30
-
31
- def websocket path, &block
32
- path = ::Mustermann.new path
33
- super path, &block
34
- end
35
-
36
- def eventsource path, headers = nil, &block
37
- path = ::Mustermann.new path
38
- super path, headers, &block
39
- end
40
-
41
- def routes
42
- @routes ||= Hash.new{|h,k| h[k] = RouteMap.new}
43
- end
44
-
45
- def filter_by which, path, meth
46
- pattern = ::Mustermann.new path
47
- filters[which][pattern] ||= []
48
- filters[which][pattern] << meth
49
- end
50
-
51
- end
52
-
53
- def params
54
- @params ||= super.merge mustermann.params(request.path)
55
- end
56
-
57
- def filter which
58
- fs = self.class.filters[which][:default].dup
59
- self.class.filters[which].each do |pattern, f|
60
- if ::Mustermann === pattern and pattern.match request.path
61
- fs << [f, pattern]
62
- end
63
- end
64
- fs.each do |f|
65
- case f
66
- when UnboundMethod
67
- f.bind(self).call
68
- when Array
69
- @pre_filter_params = params
70
- @params = @pre_filter_params.merge f[1].params(request.path)
71
- f[0].each {|filter| filter.bind(self).call}
72
- @params = @pre_filter_params
73
- end
74
- end
75
- end
76
-
77
- class RouteMap
78
-
79
- def initialize
80
- @hash = Hash.new
81
- end
82
-
83
- def []= route, responder
84
- @hash[route] = responder
85
- end
86
-
87
- def [] route
88
- responder = nil
89
- if mustermann = @hash.keys.select {|k| k.match(route)}.first
90
- responder = @hash.fetch mustermann
91
- responder.mustermann = mustermann
92
- end
93
- responder
94
- end
95
- end
96
-
97
- end
98
- end