Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
073152ee
Commit
073152ee
authored
Jun 08, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract the Tempfile generation into a factory
parent
b920ee4d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
11 deletions
+36
-11
lib/paperclip.rb
+1
-0
lib/paperclip/io_adapters/abstract_adapter.rb
+1
-11
lib/paperclip/tempfile_factory.rb
+21
-0
test/tempfile_factory_test.rb
+13
-0
No files found.
lib/paperclip.rb
View file @
073152ee
...
@@ -34,6 +34,7 @@ require 'paperclip/processor'
...
@@ -34,6 +34,7 @@ require 'paperclip/processor'
require
'paperclip/tempfile'
require
'paperclip/tempfile'
require
'paperclip/thumbnail'
require
'paperclip/thumbnail'
require
'paperclip/interpolations'
require
'paperclip/interpolations'
require
'paperclip/tempfile_factory'
require
'paperclip/style'
require
'paperclip/style'
require
'paperclip/attachment'
require
'paperclip/attachment'
require
'paperclip/attachment_options'
require
'paperclip/attachment_options'
...
...
lib/paperclip/io_adapters/abstract_adapter.rb
View file @
073152ee
module
Paperclip
module
Paperclip
class
AbstractAdapter
class
AbstractAdapter
ILLEGAL_FILENAME_CHARACTERS
=
/^~/
private
private
def
destination
def
destination
if
@destination
.
nil?
@destination
||=
TempfileFactory
.
new
.
generate
(
original_filename
)
extension
=
File
.
extname
(
original_filename
)
basename
=
File
.
basename
(
original_filename
,
extension
)
basename
=
basename
.
gsub
(
ILLEGAL_FILENAME_CHARACTERS
,
'_'
)
dest
=
Tempfile
.
new
([
basename
,
extension
])
dest
.
binmode
@destination
=
dest
end
@destination
end
end
def
copy_to_tempfile
(
src
)
def
copy_to_tempfile
(
src
)
...
...
lib/paperclip/tempfile_factory.rb
0 → 100644
View file @
073152ee
module
Paperclip
class
TempfileFactory
ILLEGAL_FILENAME_CHARACTERS
=
/^~/
def
generate
(
name
)
@name
=
name
file
=
Tempfile
.
new
([
basename
,
extension
])
file
.
binmode
file
end
def
extension
File
.
extname
(
@name
)
end
def
basename
File
.
basename
(
@name
,
extension
).
gsub
(
ILLEGAL_FILENAME_CHARACTERS
,
'_'
)
end
end
end
test/tempfile_factory_test.rb
0 → 100644
View file @
073152ee
require
'./test/helper'
class
Paperclip
::
TempfileFactoryTest
<
Test
::
Unit
::
TestCase
should
"be able to generate a tempfile with the right name"
do
file
=
subject
.
generate
(
"omg.png"
)
end
should
"be able to generate a tempfile with the right name with a tilde at the beginning"
do
file
=
subject
.
generate
(
"~omg.png"
)
end
should
"be able to generate a tempfile with the right name with a tilde at the end"
do
file
=
subject
.
generate
(
"omg.png~"
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment