about summary refs log tree commit diff
path: root/lib/paperclip/schema_extensions.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-05-07 18:21:59 +0200
committerClaire <claire.github-309c@sitedethib.com>2021-05-07 18:21:59 +0200
commit50b430d9a2857edf8ab44e9b94c7bcb14ecd2117 (patch)
tree4932ca1d8e52f6ce9b8b9fbb304b6bfce4027e54 /lib/paperclip/schema_extensions.rb
parenta346912030012dc1451249373ff7ef1a61016517 (diff)
parentd8e0c8a89e1f1dd1c4ce1513deaeb3c85c6e4a42 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
- `app/views/statuses/_simple_status.html.haml`:
  Small markup change in glitch-soc, on a line that has been modified by
  upstream. Ported upstream changes.
Diffstat (limited to 'lib/paperclip/schema_extensions.rb')
-rw-r--r--lib/paperclip/schema_extensions.rb37
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)