nozzle 0.1.5 → 0.1.6
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/nozzle/adapter/base.rb +31 -3
- data/lib/nozzle/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 319a9dafc695844ec3d4e10b020f410cd3dea303
|
4
|
+
data.tar.gz: 362e39bcafed2d87371edc59403911a8b2a9f2e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7311cea5c28ed74ebb42e29643578afcf3bdf1ecb65ac5c7e0280a26aa7442990b2a1e17c74de13369472bf6708d67db047a9447e91603fd0b33deac9b4eaf95
|
7
|
+
data.tar.gz: 0a139ca772a94e15205cbbc986cb9dcaebaea0fb4e6917594b2884fbc9180409b5327b6db70abbe8eca61143ba96cbc9d76e94213ee5927aa32e15de12de3a97
|
data/lib/nozzle/adapter/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'tmpdir'
|
2
3
|
require 'tempfile'
|
3
4
|
require 'nozzle/adapter/outlet'
|
4
5
|
|
@@ -7,6 +8,9 @@ module Nozzle
|
|
7
8
|
class Base
|
8
9
|
include Nozzle::Adapter::Outlet
|
9
10
|
|
11
|
+
# minimum filename length for Nozzle to try and fit it to the filesystem.
|
12
|
+
MIN_PATH_MAX = 255
|
13
|
+
|
10
14
|
# Initializes internal structure of new adapter.
|
11
15
|
# outlet_class.new( instance, :avatar, 'image.jpg', :fake => true )
|
12
16
|
def initialize( record, column, filename, options = {} )
|
@@ -168,7 +172,7 @@ module Nozzle
|
|
168
172
|
|
169
173
|
@tempfile_path = File.expand_path(new_path)
|
170
174
|
detect_properties
|
171
|
-
@filename = prepare_filename(filename_candidate)
|
175
|
+
@filename = fit_to_filesystem(prepare_filename(filename_candidate))
|
172
176
|
end
|
173
177
|
|
174
178
|
# Stores temporary filename by the constructed path. Deletes old file.
|
@@ -203,7 +207,7 @@ module Nozzle
|
|
203
207
|
{ :url => url }
|
204
208
|
end
|
205
209
|
|
206
|
-
|
210
|
+
private
|
207
211
|
|
208
212
|
# Returns a filename prepared for saving. Should be overridden.
|
209
213
|
# instance.avatar.new_filename('image.jpg') # => '0006-avatary-image.jpg'
|
@@ -211,6 +215,31 @@ module Nozzle
|
|
211
215
|
candidate
|
212
216
|
end
|
213
217
|
|
218
|
+
# Returns a filename that will be acceptable for filesystem
|
219
|
+
# chopping it if nessesary.
|
220
|
+
def fit_to_filesystem(candidate)
|
221
|
+
return candidate if candidate.bytesize <= MIN_PATH_MAX
|
222
|
+
ext = File.extname(candidate)
|
223
|
+
base = File.basename(candidate, ext)
|
224
|
+
tmp = Dir.tmpdir
|
225
|
+
loop do
|
226
|
+
begin
|
227
|
+
candidate = base + ext
|
228
|
+
try_file = File.join(tmp, candidate)
|
229
|
+
FileUtils.touch try_file
|
230
|
+
FileUtils.rm try_file
|
231
|
+
return candidate
|
232
|
+
rescue Errno::ENAMETOOLONG
|
233
|
+
if base.length > 0
|
234
|
+
base.chop!
|
235
|
+
retry
|
236
|
+
else
|
237
|
+
raise
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
214
243
|
# Tries to detect content_type and size of the file.
|
215
244
|
# Note: this method calls `file` system command to detect file content type.
|
216
245
|
def detect_properties
|
@@ -254,7 +283,6 @@ module Nozzle
|
|
254
283
|
FileUtils.rmdir file_path
|
255
284
|
end
|
256
285
|
end
|
257
|
-
|
258
286
|
end
|
259
287
|
end
|
260
288
|
end
|
data/lib/nozzle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nozzle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Bochkariov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.2.
|
103
|
+
rubygems_version: 2.2.1
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: A gem to store and serve attachments for ruby rack applications
|