Sha256: c2693abe47962e00de230fc8e2f1fb0f0441a0d9b1de833762b6cfbc88ec4832

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

module Paperclip
  # Provides two helpers that can be used in migrations.
  #
  # In order to use this module, the target class should implement a
  # +column+ method that takes the column name and type, both as symbols,
  # as well as a +remove_column+ method that takes a table and column name,
  # also both symbols.
  module Schema
    @@columns = {:file_name    => :string,
                 :content_type => :string,
                 :file_size    => :integer,
                 :updated_at   => :datetime}

    def has_attached_file(attachment_name)
      with_columns_for(attachment_name) do |column_name, column_type|
        column(column_name, column_type)
      end
    end

    def drop_attached_file(table_name, attachment_name)
      with_columns_for(attachment_name) do |column_name, column_type|
        remove_column(table_name, column_name)
      end
    end

    protected

    def with_columns_for(attachment_name)
      @@columns.each do |suffix, column_type|
        column_name = full_column_name(attachment_name, suffix)
        yield column_name, column_type
      end
    end

    def full_column_name(attachment_name, column_name)
      "#{attachment_name}_#{column_name}".to_sym
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
paperclip-v2_7-patched-ruby-1_8_6-2.7.5 lib/paperclip/schema.rb
paperclip-2.7.5 lib/paperclip/schema.rb
paperclip-2.7.4 lib/paperclip/schema.rb
paperclip-2.7.2 lib/paperclip/schema.rb
paperclip-2.8.0 lib/paperclip/schema.rb
paperclip-2.7.1 lib/paperclip/schema.rb
paperclip-3.0.4 lib/paperclip/schema.rb
paperclip-3.0.3 lib/paperclip/schema.rb
cloudfuji_paperclip-3.0.3 lib/paperclip/schema.rb
cloudfuji_paperclip-2.4.6 lib/paperclip/schema.rb
paperclip-3.0.2 lib/paperclip/schema.rb
paperclip-2.7.0 lib/paperclip/schema.rb
paperclip-2.6.0 lib/paperclip/schema.rb
paperclip-2.5.2 lib/paperclip/schema.rb
paperclip-2.5.1 lib/paperclip/schema.rb
paperclip-2.5.0 lib/paperclip/schema.rb