Skip to content

Instantly share code, notes, and snippets.

View vala's full-sized avatar

Valentin Ballestrino vala

  • Sainte-Agnès, France
View GitHub Profile
@vala
vala / paperclip_global_reprocessor.rb
Created July 4, 2017 21:52
Reprocess all attachments from all models of the app and engines
class PaperclipGlobalReprocessor
def run
models.each do |model|
attachments = model.try(:attachment_definitions).try(:keys)
next unless attachments
model.find_each do |resource|
attachments.each do |attachment|
resource.send(attachment).reprocess! if resource.send(:"#{ attachment }?")
@vala
vala / replace_models_assets_url.rake
Created February 22, 2016 11:02
Simple script to allowing to migrate hardcoded URLs in model fields to other hosts
#!/usr/bin/env ruby
#
# This script allows for parsing every models of your app, looking for string
# and text fields, then replacing every previous hardcoded URL with a new
# URL reflecting your new assets location
#
# Example usage :
#
# # Replace all URLs targeting an S3 bucket to a locale system URL
# rake replace_models_assets_url MATCHER="http://s3.amazonaws.com/mybucket/" REPLACEMENT="/system/"