Sha256: aaed165ba38cda955e8a7d5657064ca2cb345615efd1db43c1c596d48a09e83a

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'rails/generators/active_record'

module PaperclipDatabase
  module Generators
    class MigrationGenerator < ActiveRecord::Generators::Base
      desc "Create a migration to add database storage for the paperclip database storage." +
        "The NAME argument is the name of your model, and the following " +
        "arguments are the name of the attachments"

      argument :attachment_names,
      :required => true,
      :type => :array,
      :desc => "The names of the attachment(s) to add.",
      :banner => "attachment_one attachment_two attachment_three ..."

      def self.source_root
        @source_root ||= File.expand_path('../templates', __FILE__)
      end

      def generate_migration
        migration_template "migration.rb.erb", "db/migrate/#{migration_file_name}"
      end

      protected

      def migration_name
        "create_#{name.underscore}_#{attachment_names.map{|n| n.pluralize}.join('_and_')}"
      end

      def migration_file_name
        "#{migration_name}.rb"
      end

      def migration_class_name
        migration_name.camelize
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paperclip_database-2.0.0 lib/generators/paperclip_database/migration/migration_generator.rb
paperclip_database-1.0.5 lib/generators/paperclip_database/migration/migration_generator.rb