ftpmvc 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d700986fcf31bb2aa4321ab798886546bd8d018
4
- data.tar.gz: 1fa9c85f95fb7d60956c0a68f2a4d3177d7469f1
3
+ metadata.gz: c1ce45b7b3c0fff939bd7cc90a3806c70b41eb18
4
+ data.tar.gz: 45757c6f7f22060f65a9862bb965e0800df7f937
5
5
  SHA512:
6
- metadata.gz: 4408ed3ff3689c6ade5af7946a9825fe20227684a3564ec910e156c0ec5b70c31f21afa9b46a8a534537a13ac3ba131a0d623a6a4a34904846fe4767fc39560c
7
- data.tar.gz: bda295c20d059283c9c448059be5fd07e9f27873bd85c97b5525d5f1d8e888374f8d1a6aab6786d84936adc93d1a52f58708674895222ab3f752ae044d2d64b8
6
+ metadata.gz: 454896b3e3856d5ab9dc01035d002acb2d9b5962c424574e1e77fe621b86e48ff4dd5fe1c7ebb71124e6b9d317d1e2c04292951328a717e3af4c7e83adf31482
7
+ data.tar.gz: ff6da3c34fa074407dce7f2601ad0445b73b6002ce31fed4f05feab0a9096df96be7bdd66b9611cf9b9b3b853cdfbffa50cabb5f975ff43b608ed1265c53af32
@@ -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 do |e|
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
@@ -1,3 +1,3 @@
1
1
  module FTPMVC
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftpmvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aizim Kelmanson