lib/paperclip/schema.rb in kt-paperclip-5.4.0 vs lib/paperclip/schema.rb in kt-paperclip-6.2.0

- old
+ new

@@ -1,38 +1,42 @@ -require 'active_support/deprecation' +require "active_support/deprecation" module Paperclip # Provides helper methods that can be used in migrations. module Schema - COLUMNS = {:file_name => :string, - :content_type => :string, - :file_size => :integer, - :updated_at => :datetime} + COLUMNS = { file_name: :string, + content_type: :string, + file_size: :bigint, + updated_at: :datetime }.freeze - def self.included(base) - ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition - ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition - ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements - ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder + def self.included(_base) + ActiveRecord::ConnectionAdapters::Table.include TableDefinition + ActiveRecord::ConnectionAdapters::TableDefinition.include TableDefinition + ActiveRecord::ConnectionAdapters::AbstractAdapter.include Statements + ActiveRecord::Migration::CommandRecorder.include CommandRecorder end module Statements 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? + if attachment_names.empty? + raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration." + end 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) + add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) end end end def remove_attachment(table_name, *attachment_names) - raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty? + if attachment_names.empty? + raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." + end attachment_names.each do |attachment_name| COLUMNS.keys.each do |column_name| remove_column(table_name, "#{attachment_name}_#{column_name}") end @@ -49,10 +53,10 @@ 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) + column("#{attachment_name}_#{column_name}", column_type, column_options) end end end def has_attached_file(*attachment_names)