ftpmvc 0.5.0 → 0.6.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/lib/ftpmvc/application.rb +10 -0
- data/lib/ftpmvc/server.rb +1 -4
- data/lib/ftpmvc/version.rb +1 -1
- data/spec/lib/ftpmvc/application_spec.rb +25 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ce45b7b3c0fff939bd7cc90a3806c70b41eb18
|
4
|
+
data.tar.gz: 45757c6f7f22060f65a9862bb965e0800df7f937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454896b3e3856d5ab9dc01035d002acb2d9b5962c424574e1e77fe621b86e48ff4dd5fe1c7ebb71124e6b9d317d1e2c04292951328a717e3af4c7e83adf31482
|
7
|
+
data.tar.gz: ff6da3c34fa074407dce7f2601ad0445b73b6002ce31fed4f05feab0a9096df96be7bdd66b9611cf9b9b3b853cdfbffa50cabb5f975ff43b608ed1265c53af32
|
data/lib/ftpmvc/application.rb
CHANGED
@@ -6,6 +6,7 @@ require 'ftpmvc/authenticator/promiscuous'
|
|
6
6
|
|
7
7
|
module FTPMVC
|
8
8
|
class Application
|
9
|
+
include Logger
|
9
10
|
extend Forwardable
|
10
11
|
|
11
12
|
def_delegators :@filter_chain, :index, :get, :directory?, :exists?, :put
|
@@ -21,8 +22,17 @@ module FTPMVC
|
|
21
22
|
@authenticator ||= Authenticator::Promiscuous.new
|
22
23
|
end
|
23
24
|
|
25
|
+
def handle_exception(e)
|
26
|
+
logger.error %Q[#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}]
|
27
|
+
@exception_handler.call(e) unless @exception_handler.nil?
|
28
|
+
end
|
29
|
+
|
24
30
|
protected
|
25
31
|
|
32
|
+
def on_exception(&block)
|
33
|
+
@exception_handler = block
|
34
|
+
end
|
35
|
+
|
26
36
|
def filter(filter_class, options={})
|
27
37
|
@filter_chain = filter_class.new(@fs, @filter_chain, options)
|
28
38
|
end
|
data/lib/ftpmvc/server.rb
CHANGED
@@ -14,10 +14,7 @@ module FTPMVC
|
|
14
14
|
driver = Ftpd::Driver.new(application)
|
15
15
|
@server = ::Ftpd::FtpServer.new(driver)
|
16
16
|
@server.interface, @server.port = @address, @port
|
17
|
-
@server.on_exception
|
18
|
-
puts e
|
19
|
-
puts e.backtrace
|
20
|
-
end
|
17
|
+
@server.on_exception { |e| application.handle_exception(e) }
|
21
18
|
@server.start
|
22
19
|
@port = @server.bound_port
|
23
20
|
self
|
data/lib/ftpmvc/version.rb
CHANGED
@@ -93,4 +93,29 @@ describe FTPMVC::Application do
|
|
93
93
|
expect(application.authenticate('fabio', 'iS2grails')).to be true
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
describe '#handle_exception' do
|
98
|
+
let(:exception) { Exception.new }
|
99
|
+
let(:application) do
|
100
|
+
handler = lambda { |e| @exception_handler_executed = true }
|
101
|
+
FTPMVC::Application.new do
|
102
|
+
on_exception(&handler)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
before do
|
106
|
+
exception.set_backtrace([])
|
107
|
+
end
|
108
|
+
it 'calls exception handler' do
|
109
|
+
application.handle_exception(exception)
|
110
|
+
expect(@exception_handler_executed).to be true
|
111
|
+
end
|
112
|
+
context 'when exception handler is not defined' do
|
113
|
+
let(:application) do
|
114
|
+
FTPMVC::Application.new
|
115
|
+
end
|
116
|
+
it 'does not call nil' do
|
117
|
+
expect { application.handle_exception(exception) }.to_not raise_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
96
121
|
end
|