Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Interpolate URLs using a string rather than a regex #1940

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/paperclip/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.all
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|
result.gsub(":#{tag}") do |match|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused block argument - match. You can omit the argument if you don't care about it.

send( tag, *args )
end
end
Expand Down
10 changes: 9 additions & 1 deletion spec/paperclip/interpolations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def url(*args)
attachment.stubs(:original_filename).returns("one")
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
end

it "returns the basename when the extension contains regexp special characters" do
attachment = mock
attachment.stubs(:styles).returns({})
Expand Down Expand Up @@ -249,4 +249,12 @@ def url(*args)
value = Paperclip::Interpolations.interpolate(":notreal/:id/:attachment", :attachment, :style)
assert_equal ":notreal/1234/attachments", value
end

it "handles question marks" do
Paperclip.interpolates :foo? do
"bar"
end
value = Paperclip::Interpolations.interpolate(":fo/:foo?")
assert_equal ":fo/bar", value
end
end