app/models/pageflow/url_template.rb in pageflow-12.0.4 vs app/models/pageflow/url_template.rb in pageflow-12.1.0
- old
+ new
@@ -1,13 +1,19 @@
module Pageflow
module UrlTemplate
- module_function
+ extend self
def from_attachment(attachment, *style)
insert_id_partition_placeholder(attachment.url(*style))
end
+ private
+
def insert_id_partition_placeholder(url)
- url.gsub(%r'(\d{3}/)+', ':id_partition/')
+ replace_last_group_of_digit_segments(url, with: '/:id_partition/')
+ end
+
+ def replace_last_group_of_digit_segments(str, with:)
+ str.reverse.sub(%r'/(\d{3}/)+', with.reverse).reverse
end
end
end