forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix older migrations on Ruby 3 (mastodon#16174)
- Loading branch information
1 parent
0ad240c
commit a5f91a1
Showing
3 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Monkey-patch various Paperclip methods for Ruby 3.0 compatibility | ||
|
||
module Paperclip | ||
module Schema | ||
module StatementsExtensions | ||
def add_attachment(table_name, *attachment_names) | ||
raise ArgumentError, 'Please specify attachment name in your add_attachment call in your migration.' if attachment_names.empty? | ||
|
||
options = attachment_names.extract_options! | ||
|
||
attachment_names.each do |attachment_name| | ||
COLUMNS.each_pair do |column_name, column_type| | ||
column_options = options.merge(options[column_name.to_sym] || {}) | ||
add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options) | ||
end | ||
end | ||
end | ||
end | ||
|
||
module TableDefinitionExtensions | ||
def attachment(*attachment_names) | ||
options = attachment_names.extract_options! | ||
attachment_names.each do |attachment_name| | ||
COLUMNS.each_pair do |column_name, column_type| | ||
column_options = options.merge(options[column_name.to_sym] || {}) | ||
column("#{attachment_name}_#{column_name}", column_type, **column_options) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Paperclip::Schema::Statements.prepend(Paperclip::Schema::StatementsExtensions) | ||
Paperclip::Schema::TableDefinition.prepend(Paperclip::Schema::TableDefinitionExtensions) |