paperclip-storage-ftp 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +5 -0
- data/lib/paperclip/storage/ftp.rb +22 -9
- data/paperclip-storage-ftp.gemspec +1 -1
- data/spec/paperclip/storage/ftp_spec.rb +43 -18
- data/spec/support/integration/ftp_server.rb +7 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ac0615dacb3edb9fd6ed435afa757d631e96946
|
4
|
+
data.tar.gz: 78db92783d426bb615b9beef8133d2e717d69740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42bcf600a6cddde9324da644dfbed5de0d4af895318041cd357772bd48a59a15c38537579037701e8fecbccc5578474efd19130c6842875f08fac4757644461
|
7
|
+
data.tar.gz: ac45ef8e943368a069369c5c56d7645c740f1124d28b72e768205692653fda754bb323584baa5047fbfd1174fb0cffafcc9fe531193ba29cf5018a96734225bd
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -79,6 +79,11 @@ end
|
|
79
79
|
|
80
80
|
## Changelog
|
81
81
|
|
82
|
+
### 1.2.1
|
83
|
+
|
84
|
+
* Raise `Paperclip::Storage::Ftp::NoServerAvailable` error when using `:ftp_ignore_failing_connections => true` but all servers are down
|
85
|
+
* Avoid connecting to all servers for operations that just need one
|
86
|
+
|
82
87
|
### 1.2.0
|
83
88
|
|
84
89
|
* New options `:ftp_connect_timeout` and `:ftp_ignore_failing_connections`. See usage example above.
|
@@ -7,6 +7,9 @@ require "paperclip/storage/ftp/server"
|
|
7
7
|
module Paperclip
|
8
8
|
module Storage
|
9
9
|
module Ftp
|
10
|
+
|
11
|
+
class NoServerAvailable < StandardError; end
|
12
|
+
|
10
13
|
def exists?(style_name = default_style)
|
11
14
|
return false unless original_filename
|
12
15
|
with_primary_ftp_server do |server|
|
@@ -80,7 +83,11 @@ module Paperclip
|
|
80
83
|
end
|
81
84
|
|
82
85
|
def primary_ftp_server
|
83
|
-
ftp_servers.
|
86
|
+
@options[:ftp_servers].each do |server_options|
|
87
|
+
server = build_and_connect_server(server_options)
|
88
|
+
return server if server.connected?
|
89
|
+
end
|
90
|
+
raise NoServerAvailable
|
84
91
|
end
|
85
92
|
|
86
93
|
def with_ftp_servers(&blk)
|
@@ -93,15 +100,21 @@ module Paperclip
|
|
93
100
|
end
|
94
101
|
|
95
102
|
def ftp_servers
|
96
|
-
|
97
|
-
|
98
|
-
:connect_timeout => @options[:ftp_connect_timeout],
|
99
|
-
:ignore_connect_errors => @options[:ftp_ignore_failing_connections]
|
100
|
-
))
|
101
|
-
server.establish_connection
|
102
|
-
server
|
103
|
+
servers = @options[:ftp_servers].map do |server_options|
|
104
|
+
build_and_connect_server(server_options)
|
103
105
|
end
|
104
|
-
|
106
|
+
available_servers = servers.select{|s| s.connected? }
|
107
|
+
raise NoServerAvailable if available_servers.empty?
|
108
|
+
available_servers
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_and_connect_server(server_options)
|
112
|
+
server = Server.new(server_options.merge(
|
113
|
+
:connect_timeout => @options[:ftp_connect_timeout],
|
114
|
+
:ignore_connect_errors => @options[:ftp_ignore_failing_connections]
|
115
|
+
))
|
116
|
+
server.establish_connection
|
117
|
+
server
|
105
118
|
end
|
106
119
|
end
|
107
120
|
end
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
13
|
gem.name = "paperclip-storage-ftp"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "1.2.
|
15
|
+
gem.version = "1.2.1"
|
16
16
|
|
17
17
|
gem.add_dependency("paperclip")
|
18
18
|
|
@@ -149,9 +149,24 @@ describe Paperclip::Storage::Ftp do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
context "#primary_ftp_server" do
|
152
|
-
it "returns the first server
|
153
|
-
|
154
|
-
attachment.
|
152
|
+
it "returns the first configured server" do
|
153
|
+
first_server.stub(:connected? => true)
|
154
|
+
attachment.stub(:build_and_connect_server).and_return(first_server)
|
155
|
+
attachment.primary_ftp_server.should == first_server
|
156
|
+
end
|
157
|
+
|
158
|
+
it "returns the second server if first server is down" do
|
159
|
+
first_server.stub(:connected? => false)
|
160
|
+
second_server.stub(:connected? => true)
|
161
|
+
attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
|
162
|
+
attachment.primary_ftp_server.should == second_server
|
163
|
+
end
|
164
|
+
|
165
|
+
it "raises NoServerAvailable error if all servers are down" do
|
166
|
+
first_server.stub(:connected? => false)
|
167
|
+
second_server.stub(:connected? => false)
|
168
|
+
attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
|
169
|
+
expect { attachment.primary_ftp_server }.to raise_error(Paperclip::Storage::Ftp::NoServerAvailable)
|
155
170
|
end
|
156
171
|
end
|
157
172
|
|
@@ -166,21 +181,31 @@ describe Paperclip::Storage::Ftp do
|
|
166
181
|
|
167
182
|
context "#ftp_servers" do
|
168
183
|
it "returns the configured ftp servers" do
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
attachment.ftp_servers.
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
attachment.
|
179
|
-
attachment.ftp_servers.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
+
first_server.stub(:connected? => true)
|
185
|
+
second_server.stub(:connected? => true)
|
186
|
+
attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
|
187
|
+
attachment.ftp_servers.should == [first_server, second_server]
|
188
|
+
end
|
189
|
+
|
190
|
+
it "raises NoServerAvailable error if all servers are down" do
|
191
|
+
first_server.stub(:connected? => false)
|
192
|
+
second_server.stub(:connected? => false)
|
193
|
+
attachment.stub(:build_and_connect_server).and_return(first_server, second_server)
|
194
|
+
expect { attachment.ftp_servers }.to raise_error(Paperclip::Storage::Ftp::NoServerAvailable)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "#build_and_connect_server" do
|
199
|
+
it "returns a connected server instance based on the given options" do
|
200
|
+
Paperclip::Storage::Ftp::Server.stub(:new).and_call_original
|
201
|
+
|
202
|
+
expected_options = attachment.options[:ftp_servers].first.merge(
|
203
|
+
:connect_timeout => attachment.options[:ftp_connect_timeout],
|
204
|
+
:ignore_connect_errors => attachment.options[:ftp_ignore_failing_connections]
|
205
|
+
)
|
206
|
+
expect(first_server).to receive(:establish_connection)
|
207
|
+
Paperclip::Storage::Ftp::Server.stub(:new).with(expected_options).and_return(first_server)
|
208
|
+
attachment.build_and_connect_server(attachment.options[:ftp_servers].first).should == first_server
|
184
209
|
end
|
185
210
|
end
|
186
211
|
end
|
@@ -23,12 +23,13 @@ class FtpServer
|
|
23
23
|
|
24
24
|
def self.daemon_controller
|
25
25
|
@daemon_controller ||= DaemonController.new(
|
26
|
-
:identifier
|
27
|
-
:start_command
|
28
|
-
:ping_command
|
29
|
-
:pid_file
|
30
|
-
:log_file
|
31
|
-
:start_timeout
|
26
|
+
:identifier => "Apache FtpServer",
|
27
|
+
:start_command => "cd #{INSTALL_PATH}; ./bin/ftpd.sh res/conf/ftpd-typical.xml",
|
28
|
+
:ping_command => [:tcp, '127.0.0.1', 2121],
|
29
|
+
:pid_file => INSTALL_PATH + "/res/ftpd.pid",
|
30
|
+
:log_file => INSTALL_PATH + "/res/log/ftpd.log",
|
31
|
+
:start_timeout => ENV['TRAVIS'] ? 120 : 10,
|
32
|
+
:log_file_activity_timeout => ENV['TRAVIS'] ? 120 : 10
|
32
33
|
)
|
33
34
|
end
|
34
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-storage-ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Röbke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
version_requirements: !ruby/object:Gem::Requirement
|