diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-05-07 15:56:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 15:56:45 +0200 |
commit | a5f91a11d07db93526597131100c919f21a5dd78 (patch) | |
tree | fc51cd3cc48942fa4f5689ee0ac57f6a4fa173ab /lib/paperclip | |
parent | 0ad240cb6b8662e31dfae6279cbee07a4c75b231 (diff) |
Fix older migrations on Ruby 3 (#16174)
Diffstat (limited to 'lib/paperclip')
-rw-r--r-- | lib/paperclip/schema_extensions.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/paperclip/schema_extensions.rb b/lib/paperclip/schema_extensions.rb new file mode 100644 index 000000000..8d065676a --- /dev/null +++ b/lib/paperclip/schema_extensions.rb @@ -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) |