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
68aea16f
Commit
68aea16f
authored
Jun 15, 2012
by
Geoffrey Hichborn
Committed by
Jon Yurek
Nov 26, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented performance improvement to interpolator
parent
c0c1f1ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
9 deletions
+5
-9
lib/paperclip/interpolations.rb
+3
-6
test/attachment_test.rb
+2
-2
test/interpolations_test.rb
+0
-1
No files found.
lib/paperclip/interpolations.rb
View file @
68aea16f
...
...
@@ -27,12 +27,9 @@ module Paperclip
# and the arguments to pass, which are the attachment and style name.
# You can pass a method name on your record as a symbol, which should turn
# an interpolation pattern for Paperclip to use.
def
self
.
interpolate
pattern
,
*
args
pattern
=
args
.
first
.
instance
.
send
(
pattern
)
if
pattern
.
kind_of?
Symbol
all
.
reverse
.
inject
(
pattern
)
do
|
result
,
tag
|
result
.
gsub
(
/:
#{
tag
}
/
)
do
|
match
|
send
(
tag
,
*
args
)
end
def
self
.
interpolate
(
pattern
,
*
args
)
pattern
.
gsub
/:([[:word:]]+)/
do
Paperclip
::
Interpolations
.
respond_to?
(
$1
)
?
Paperclip
::
Interpolations
.
send
(
$1
,
*
args
)
:
":
#{
$1
}
"
end
end
...
...
test/attachment_test.rb
View file @
68aea16f
...
...
@@ -282,8 +282,8 @@ class AttachmentTest < Test::Unit::TestCase
teardown
{
@file
.
close
}
should
"make sure that they are interpolated correctly"
do
assert_equal
"1024.omg/1024-bbq/
1024
what/000/001/024.wtf"
,
@dummy
.
avatar
.
path
should
"make sure that they are interpolated correctly
as long non-word characters separate them
"
do
assert_equal
"1024.omg/1024-bbq/
:id
what/000/001/024.wtf"
,
@dummy
.
avatar
.
path
end
end
...
...
test/interpolations_test.rb
View file @
68aea16f
...
...
@@ -231,7 +231,6 @@ class InterpolationsTest < Test::Unit::TestCase
should
"call all expected interpolations with the given arguments"
do
Paperclip
::
Interpolations
.
expects
(
:id
).
with
(
:attachment
,
:style
).
returns
(
1234
)
Paperclip
::
Interpolations
.
expects
(
:attachment
).
with
(
:attachment
,
:style
).
returns
(
"attachments"
)
Paperclip
::
Interpolations
.
expects
(
:notreal
).
never
value
=
Paperclip
::
Interpolations
.
interpolate
(
":notreal/:id/:attachment"
,
:attachment
,
:style
)
assert_equal
":notreal/1234/attachments"
,
value
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