deas 0.43.0 → 0.43.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deas/route.rb +7 -0
- data/lib/deas/server.rb +30 -11
- data/lib/deas/server_data.rb +14 -9
- data/lib/deas/sinatra_app.rb +6 -4
- data/lib/deas/version.rb +1 -1
- data/test/unit/error_handler_tests.rb +5 -3
- data/test/unit/route_tests.rb +47 -2
- data/test/unit/server_data_tests.rb +28 -17
- data/test/unit/server_tests.rb +15 -0
- data/test/unit/sinatra_app_tests.rb +15 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: a7ed98879ce4a9d86af5566709fe01be46427628d0baebc35c26ac81e2f40dfa7f898c44fcd9300786ef6428386aea84cd196bd94fe5368b226b7575cc05250c
|
4
|
+
data.tar.gz: 4ddcc49f557e452abdae183b326c70b9e3fbef06a22aa74d3888d2daceec2864911caa45f9cb1869d1dd7b3b9f3272b9d9d16327bdcb7a845ca1db3f2eb1509d
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: efa732131bcecfd7712c8f4dfce268c51f78063f
|
7
|
+
data.tar.gz: ca2a30817b98efa05ee407d93c5626b3c236873a
|
data/lib/deas/route.rb
CHANGED
@@ -17,11 +17,18 @@ module Deas
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def run(server_data, request_data)
|
20
|
+
server_data.before_route_run_procs.each do |c|
|
21
|
+
c.call(server_data, request_data)
|
22
|
+
end
|
20
23
|
request_type_name = server_data.router.request_type_name(request_data.request)
|
21
24
|
begin
|
22
25
|
@handler_proxies[request_type_name].run(server_data, request_data)
|
23
26
|
rescue HandlerProxyNotFound
|
24
27
|
[404, Rack::Utils::HeaderHash.new, []]
|
28
|
+
ensure
|
29
|
+
server_data.after_route_run_procs.each do |c|
|
30
|
+
c.call(server_data, request_data)
|
31
|
+
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
data/lib/deas/server.rb
CHANGED
@@ -92,6 +92,22 @@ module Deas
|
|
92
92
|
self.config.error_procs
|
93
93
|
end
|
94
94
|
|
95
|
+
def before_route_run(&block)
|
96
|
+
self.config.before_route_run_procs << block
|
97
|
+
end
|
98
|
+
|
99
|
+
def before_route_run_procs
|
100
|
+
self.config.before_route_run_procs
|
101
|
+
end
|
102
|
+
|
103
|
+
def after_route_run(&block)
|
104
|
+
self.config.after_route_run_procs << block
|
105
|
+
end
|
106
|
+
|
107
|
+
def after_route_run_procs
|
108
|
+
self.config.after_route_run_procs
|
109
|
+
end
|
110
|
+
|
95
111
|
def template_source(value = nil)
|
96
112
|
self.config.template_source = value if !value.nil?
|
97
113
|
self.config.template_source
|
@@ -121,20 +137,23 @@ module Deas
|
|
121
137
|
attr_accessor :env, :root
|
122
138
|
attr_accessor :method_override, :show_exceptions, :verbose_logging
|
123
139
|
attr_accessor :middlewares, :init_procs, :error_procs
|
140
|
+
attr_accessor :before_route_run_procs, :after_route_run_procs
|
124
141
|
attr_accessor :template_source, :logger, :router
|
125
142
|
|
126
143
|
def initialize
|
127
|
-
@env
|
128
|
-
@root
|
129
|
-
@method_override
|
130
|
-
@show_exceptions
|
131
|
-
@verbose_logging
|
132
|
-
@middlewares
|
133
|
-
@init_procs
|
134
|
-
@error_procs
|
135
|
-
@
|
136
|
-
@
|
137
|
-
@
|
144
|
+
@env = DEFAULT_ENV
|
145
|
+
@root = ENV['PWD']
|
146
|
+
@method_override = true
|
147
|
+
@show_exceptions = false
|
148
|
+
@verbose_logging = true
|
149
|
+
@middlewares = []
|
150
|
+
@init_procs = []
|
151
|
+
@error_procs = []
|
152
|
+
@before_route_run_procs = []
|
153
|
+
@after_route_run_procs = []
|
154
|
+
@template_source = nil
|
155
|
+
@logger = Deas::NullLogger.new
|
156
|
+
@router = Deas::Router.new
|
138
157
|
|
139
158
|
@valid = nil
|
140
159
|
end
|
data/lib/deas/server_data.rb
CHANGED
@@ -7,22 +7,27 @@ module Deas
|
|
7
7
|
# to provide these with a simplified interface with the minimal data needed
|
8
8
|
# and to decouple the configuration from each thing that needs its data.
|
9
9
|
|
10
|
-
attr_reader :error_procs, :
|
10
|
+
attr_reader :error_procs, :before_route_run_procs, :after_route_run_procs
|
11
|
+
attr_reader :template_source, :logger, :router
|
11
12
|
|
12
13
|
def initialize(args)
|
13
14
|
args ||= {}
|
14
|
-
@error_procs
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
15
|
+
@error_procs = args[:error_procs] || []
|
16
|
+
@before_route_run_procs = args[:before_route_run_procs] || []
|
17
|
+
@after_route_run_procs = args[:after_route_run_procs] || []
|
18
|
+
@template_source = args[:template_source]
|
19
|
+
@logger = args[:logger]
|
20
|
+
@router = args[:router]
|
18
21
|
end
|
19
22
|
|
20
23
|
def ==(other_server_data)
|
21
24
|
if other_server_data.kind_of?(ServerData)
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.
|
25
|
-
self.
|
25
|
+
self.before_route_run_procs == other_server_data.before_route_run_procs &&
|
26
|
+
self.after_route_run_procs == other_server_data.after_route_run_procs &&
|
27
|
+
self.error_procs == other_server_data.error_procs &&
|
28
|
+
self.template_source == other_server_data.template_source &&
|
29
|
+
self.logger == other_server_data.logger &&
|
30
|
+
self.router == other_server_data.router
|
26
31
|
else
|
27
32
|
super
|
28
33
|
end
|
data/lib/deas/sinatra_app.rb
CHANGED
@@ -27,10 +27,12 @@ module Deas
|
|
27
27
|
# server's initialization logic more like Sanford does.
|
28
28
|
server_config.validate!
|
29
29
|
server_data = ServerData.new({
|
30
|
-
:error_procs
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
30
|
+
:error_procs => server_config.error_procs,
|
31
|
+
:before_route_run_procs => server_config.before_route_run_procs,
|
32
|
+
:after_route_run_procs => server_config.after_route_run_procs,
|
33
|
+
:logger => server_config.logger,
|
34
|
+
:router => server_config.router,
|
35
|
+
:template_source => server_config.template_source
|
34
36
|
})
|
35
37
|
|
36
38
|
Sinatra.new do
|
data/lib/deas/version.rb
CHANGED
@@ -12,7 +12,7 @@ class Deas::ErrorHandler
|
|
12
12
|
@server_data = Factory.server_data(:error_procs => @error_proc_spies)
|
13
13
|
@request = Factory.string
|
14
14
|
@response = Factory.string
|
15
|
-
@handler_class =
|
15
|
+
@handler_class = Factory.string
|
16
16
|
@handler = Factory.string
|
17
17
|
@params = Factory.string
|
18
18
|
@splat = Factory.string
|
@@ -28,8 +28,10 @@ class Deas::ErrorHandler
|
|
28
28
|
:splat => @splat,
|
29
29
|
:route_path => @route_path
|
30
30
|
}
|
31
|
+
|
32
|
+
@error_handler_class = Deas::ErrorHandler
|
31
33
|
end
|
32
|
-
subject{ @
|
34
|
+
subject{ @error_handler_class }
|
33
35
|
|
34
36
|
should have_imeths :run
|
35
37
|
|
@@ -39,7 +41,7 @@ class Deas::ErrorHandler
|
|
39
41
|
desc "when init"
|
40
42
|
setup do
|
41
43
|
@exception = Factory.exception
|
42
|
-
@error_handler = @
|
44
|
+
@error_handler = @error_handler_class.new(@exception, @context_hash)
|
43
45
|
end
|
44
46
|
subject{ @error_handler }
|
45
47
|
|
data/test/unit/route_tests.rb
CHANGED
@@ -40,7 +40,28 @@ class Deas::Route
|
|
40
40
|
class RunTests < UnitTests
|
41
41
|
desc "when run"
|
42
42
|
setup do
|
43
|
-
@
|
43
|
+
@before_route_run_procs_called_with = nil
|
44
|
+
@before_route_run_procs_called = 0
|
45
|
+
@before_route_run_procs = Factory.integer(3).times.map do
|
46
|
+
proc do |*args|
|
47
|
+
@before_route_run_procs_called_with = args
|
48
|
+
@before_route_run_procs_called += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
@after_route_run_procs_called_with = nil
|
53
|
+
@after_route_run_procs_called = 0
|
54
|
+
@after_route_run_procs = Factory.integer(3).times.map do
|
55
|
+
proc do |*args|
|
56
|
+
@after_route_run_procs_called_with = args
|
57
|
+
@after_route_run_procs_called += 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
@server_data = Factory.server_data({
|
62
|
+
:before_route_run_procs => @before_route_run_procs,
|
63
|
+
:after_route_run_procs => @after_route_run_procs
|
64
|
+
})
|
44
65
|
@request_data = Factory.request_data
|
45
66
|
end
|
46
67
|
|
@@ -50,9 +71,33 @@ class Deas::Route
|
|
50
71
|
){ @req_type_name }
|
51
72
|
|
52
73
|
@route.run(@server_data, @request_data)
|
74
|
+
|
75
|
+
assert_equal @before_route_run_procs.size, @before_route_run_procs_called
|
76
|
+
exp = [@server_data, @request_data]
|
77
|
+
assert_equal exp, @before_route_run_procs_called_with
|
78
|
+
|
53
79
|
assert_true @proxy.run_called
|
54
|
-
assert_equal @server_data,
|
80
|
+
assert_equal @server_data, @proxy.server_data
|
55
81
|
assert_equal @request_data, @proxy.request_data
|
82
|
+
|
83
|
+
assert_equal @after_route_run_procs.size, @after_route_run_procs_called
|
84
|
+
exp = [@server_data, @request_data]
|
85
|
+
assert_equal exp, @after_route_run_procs_called_with
|
86
|
+
end
|
87
|
+
|
88
|
+
should "run after route run procs even if the proxy errored" do
|
89
|
+
Assert.stub(@server_data.router, :request_type_name).with(
|
90
|
+
@request_data.request
|
91
|
+
){ @req_type_name }
|
92
|
+
exception = Factory.exception
|
93
|
+
Assert.stub(@proxy, :run){ raise exception }
|
94
|
+
|
95
|
+
raised = assert_raises{ @route.run(@server_data, @request_data) }
|
96
|
+
assert_equal exception, raised
|
97
|
+
|
98
|
+
assert_equal @after_route_run_procs.size, @after_route_run_procs_called
|
99
|
+
exp = [@server_data, @request_data]
|
100
|
+
assert_equal exp, @after_route_run_procs_called_with
|
56
101
|
end
|
57
102
|
|
58
103
|
should "halt 404 if it can't find a proxy for the given request type name" do
|
@@ -6,33 +6,42 @@ class Deas::ServerData
|
|
6
6
|
class UnitTests < Assert::Context
|
7
7
|
desc "Deas::ServerData"
|
8
8
|
setup do
|
9
|
-
@error_procs
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
9
|
+
@error_procs = Factory.integer(3).times.map{ proc{ Factory.string } }
|
10
|
+
@before_route_run_procs = Factory.integer(3).times.map{ proc{ Factory.string } }
|
11
|
+
@after_route_run_procs = Factory.integer(3).times.map{ proc{ Factory.string } }
|
12
|
+
@logger = Factory.string
|
13
|
+
@router = Factory.string
|
14
|
+
@template_source = Factory.string
|
13
15
|
|
14
16
|
@server_data = Deas::ServerData.new({
|
15
|
-
:error_procs
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
17
|
+
:error_procs => @error_procs,
|
18
|
+
:before_route_run_procs => @before_route_run_procs,
|
19
|
+
:after_route_run_procs => @after_route_run_procs,
|
20
|
+
:logger => @logger,
|
21
|
+
:router => @router,
|
22
|
+
:template_source => @template_source
|
19
23
|
})
|
20
24
|
end
|
21
25
|
subject{ @server_data }
|
22
26
|
|
23
|
-
should have_readers :error_procs, :
|
27
|
+
should have_readers :error_procs, :before_route_run_procs, :after_route_run_procs
|
28
|
+
should have_readers :logger, :router, :template_source
|
24
29
|
|
25
30
|
should "know its attributes" do
|
26
|
-
assert_equal @error_procs,
|
27
|
-
assert_equal @
|
28
|
-
assert_equal @
|
29
|
-
assert_equal @
|
31
|
+
assert_equal @error_procs, subject.error_procs
|
32
|
+
assert_equal @before_route_run_procs, subject.before_route_run_procs
|
33
|
+
assert_equal @after_route_run_procs, subject.after_route_run_procs
|
34
|
+
assert_equal @logger, subject.logger
|
35
|
+
assert_equal @router, subject.router
|
36
|
+
assert_equal @template_source, subject.template_source
|
30
37
|
end
|
31
38
|
|
32
39
|
should "default its attributes when they aren't provided" do
|
33
40
|
server_data = Deas::ServerData.new({})
|
34
41
|
|
35
42
|
assert_equal [], server_data.error_procs
|
43
|
+
assert_equal [], server_data.before_route_run_procs
|
44
|
+
assert_equal [], server_data.after_route_run_procs
|
36
45
|
assert_nil server_data.logger
|
37
46
|
assert_nil server_data.router
|
38
47
|
assert_nil server_data.template_source
|
@@ -40,10 +49,12 @@ class Deas::ServerData
|
|
40
49
|
|
41
50
|
should "know if it is equal to another server data" do
|
42
51
|
server_data = Deas::ServerData.new({
|
43
|
-
:error_procs
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
52
|
+
:error_procs => @error_procs,
|
53
|
+
:before_route_run_procs => @before_route_run_procs,
|
54
|
+
:after_route_run_procs => @after_route_run_procs,
|
55
|
+
:logger => @logger,
|
56
|
+
:router => @router,
|
57
|
+
:template_source => @template_source
|
47
58
|
})
|
48
59
|
assert_equal server_data, subject
|
49
60
|
|
data/test/unit/server_tests.rb
CHANGED
@@ -69,6 +69,18 @@ module Deas::Server
|
|
69
69
|
assert_equal 1, config.error_procs.size
|
70
70
|
assert_equal exp, config.error_procs.first
|
71
71
|
|
72
|
+
exp = proc{ }
|
73
|
+
assert_equal 0, config.before_route_run_procs.size
|
74
|
+
subject.before_route_run(&exp)
|
75
|
+
assert_equal 1, config.before_route_run_procs.size
|
76
|
+
assert_equal exp, config.before_route_run_procs.first
|
77
|
+
|
78
|
+
exp = proc{ }
|
79
|
+
assert_equal 0, config.after_route_run_procs.size
|
80
|
+
subject.after_route_run(&exp)
|
81
|
+
assert_equal 1, config.after_route_run_procs.size
|
82
|
+
assert_equal exp, config.after_route_run_procs.first
|
83
|
+
|
72
84
|
exp = Deas::TemplateSource.new(Factory.path)
|
73
85
|
subject.template_source exp
|
74
86
|
assert_equal exp, config.template_source
|
@@ -127,6 +139,7 @@ module Deas::Server
|
|
127
139
|
should have_accessors :env, :root
|
128
140
|
should have_accessors :method_override, :show_exceptions, :verbose_logging
|
129
141
|
should have_accessors :middlewares, :init_procs, :error_procs
|
142
|
+
should have_accessors :before_route_run_procs, :after_route_run_procs
|
130
143
|
should have_accessors :template_source, :logger, :router
|
131
144
|
|
132
145
|
should have_imeths :urls, :routes
|
@@ -150,6 +163,8 @@ module Deas::Server
|
|
150
163
|
assert_equal [], subject.middlewares
|
151
164
|
assert_equal [], subject.init_procs
|
152
165
|
assert_equal [], subject.error_procs
|
166
|
+
assert_equal [], subject.before_route_run_procs
|
167
|
+
assert_equal [], subject.after_route_run_procs
|
153
168
|
|
154
169
|
assert_instance_of Deas::NullTemplateSource, subject.template_source
|
155
170
|
assert_equal subject.root, subject.template_source.path
|
@@ -36,8 +36,15 @@ module Deas::SinatraApp
|
|
36
36
|
@router.get('/something', 'EmptyViewHandler')
|
37
37
|
@router.validate!
|
38
38
|
|
39
|
-
|
40
|
-
@config
|
39
|
+
# set config attributes to make sure they are passed to the `ServerData`
|
40
|
+
@config = Deas::Server::Config.new.tap do |c|
|
41
|
+
c.error_procs = Factory.integer(3).times.map{ proc{ Factory.string } },
|
42
|
+
c.before_route_run_procs = Factory.integer(3).times.map{ proc{ Factory.string } },
|
43
|
+
c.after_route_run_procs = Factory.integer(3).times.map{ proc{ Factory.string } },
|
44
|
+
c.template_source = Factory.string,
|
45
|
+
c.logger = Factory.string,
|
46
|
+
c.router = @router
|
47
|
+
end
|
41
48
|
|
42
49
|
@sinatra_app = Deas::SinatraApp.new(@config)
|
43
50
|
end
|
@@ -58,10 +65,12 @@ module Deas::SinatraApp
|
|
58
65
|
assert_equal @config.root, s.root
|
59
66
|
|
60
67
|
exp = Deas::ServerData.new({
|
61
|
-
:error_procs
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
68
|
+
:error_procs => @config.error_procs,
|
69
|
+
:before_route_run_procs => @config.before_route_run_procs,
|
70
|
+
:after_route_run_procs => @config.after_route_run_procs,
|
71
|
+
:logger => @config.logger,
|
72
|
+
:router => @config.router,
|
73
|
+
:template_source => @config.template_source
|
65
74
|
})
|
66
75
|
assert_equal exp, s.deas_server_data
|
67
76
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.43.
|
4
|
+
version: 0.43.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-11-08 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
requirements: []
|
171
171
|
|
172
172
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.6.
|
173
|
+
rubygems_version: 2.6.7
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Handler-based web framework powered by Sinatra
|