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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -4
- data/CHANGELOG.md +22 -0
- data/Gemfile +5 -4
- data/README.md +101 -57
- data/angelo.gemspec +13 -10
- data/lib/angelo.rb +5 -2
- data/lib/angelo/base.rb +136 -54
- data/lib/angelo/main.rb +47 -0
- data/lib/angelo/minitest/helpers.rb +51 -23
- data/lib/angelo/params_parser.rb +33 -17
- data/lib/angelo/responder.rb +10 -9
- data/lib/angelo/responder/eventsource.rb +21 -20
- data/lib/angelo/responder/websocket.rb +1 -2
- data/lib/angelo/stash.rb +5 -3
- data/lib/angelo/tilt/erb.rb +38 -11
- data/lib/angelo/version.rb +1 -1
- data/test/angelo/erb_spec.rb +65 -3
- data/test/angelo/mustermann_spec.rb +1 -8
- data/test/angelo/options_spec.rb +19 -0
- data/test/angelo/params_spec.rb +27 -2
- data/test/angelo_spec.rb +18 -0
- data/test/main/app.rb +38 -0
- data/test/main/main_spec.rb +101 -0
- data/test/spec_helper.rb +7 -39
- metadata +37 -6
- data/lib/angelo/mustermann.rb +0 -98
data/lib/angelo/mustermann.rb
DELETED
@@ -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
|