schema.rb内に以下の様なコードがあるのですが、add_attachmentメソッドの中央にカラムのオプションを変数column_optionsに格納しているような記載が見られます。
options.mergeとありますが、optionsインスタンスも見当たりません。
ここで使われているoptionsインスタンスとはなんなのでしょうか?
###詳細
paperclip (5.0.0)
Rails 5.1.4
ruby
1require 'active_support/deprecation' 2 3module Paperclip 4 # Provides helper methods that can be used in migrations. 5 module Schema 6 COLUMNS = {:file_name => :string, 7 :content_type => :string, 8 :file_size => :integer, 9 :updated_at => :datetime} 10 11 def self.included(base) 12 ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition 13 ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition 14 ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements 15 ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder 16 end 17 18 module Statements 19 def add_attachment(table_name, *attachment_names) 20 raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration." if attachment_names.empty? 21 22 options = attachment_names.extract_options! 23 24 attachment_names.each do |attachment_name| 25 COLUMNS.each_pair do |column_name, column_type| 26 column_options = options.merge(options[column_name.to_sym] || {}) 27 add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options) 28 end 29 end 30 end 31 32 def remove_attachment(table_name, *attachment_names) 33 raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty? 34 35 attachment_names.each do |attachment_name| 36 COLUMNS.keys.each do |column_name| 37 remove_column(table_name, "#{attachment_name}_#{column_name}") 38 end 39 end 40 end 41 42 def drop_attached_file(*args) 43 ActiveSupport::Deprecation.warn "Method `drop_attached_file` in the migration has been deprecated and will be replaced by `remove_attachment`." 44 remove_attachment(*args) 45 end 46 end 47 48 module TableDefinition 49 def attachment(*attachment_names) 50 options = attachment_names.extract_options! 51 attachment_names.each do |attachment_name| 52 COLUMNS.each_pair do |column_name, column_type| 53 column_options = options.merge(options[column_name.to_sym] || {}) 54 column("#{attachment_name}_#{column_name}", column_type, column_options) 55 end 56 end 57 end 58 59 def has_attached_file(*attachment_names) 60 ActiveSupport::Deprecation.warn "Method `t.has_attached_file` in the migration has been deprecated and will be replaced by `t.attachment`." 61 attachment(*attachment_names) 62 end 63 end 64 65 module CommandRecorder 66 def add_attachment(*args) 67 record(:add_attachment, args) 68 end 69 70 private 71 72 def invert_add_attachment(args) 73 [:remove_attachment, args] 74 end 75 end 76 end 77end 78
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/23 07:24