Sha256: 77820c8178717b0394319f8c94bb183cf687acd47c131f5d31d1011cd9344ec0

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

module Arpa
  module Generators
    class InstallGenerator < Rails::Generators::Base
      include Rails::Generators::Migration

      source_root File.expand_path("..", __FILE__)

      desc <<-DESC.strip_heredoc
       The Name of table to create the associate table.

       E.g. users, admins.

       By default is 'users'
       DESC

      argument :associate_table, required: false

      desc <<-DESC.strip_heredoc
        The Primary key to create the associate table.

        E.g. user_id, admin_id.

        By default is 'user_id'
      DESC
      argument :associate_primary_key, required: false

      def self.next_migration_number(dirname)
        return Time.new.utc.strftime("%Y%m%d%H%M%S") if ActiveRecord::Base.timestamped_migrations
        "%.3d" % (current_migration_number(dirname) + 1)
      end

      desc "Create a migrate file with all necessery tables including the associate table."

      def create_migrate_files
        @associate_table       ||= 'users'
        @associate_primary_key ||= "#{@associate_table.singularize}_id"
        migration_template 'templates/migration.rb', 'db/migrate/create_arpa_tables.rb'
      end

      def copy_locales
        copy_file '../../config/locales/arpa.en.yml', 'config/locales/arpa.en.yml'
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arpa-0.2.0 lib/generators/arpa/install_generator.rb
arpa-0.1.0 lib/generators/arpa/install_generator.rb
arpa-0.0.9 lib/generators/arpa/install_generator.rb
arpa-0.0.8 lib/generators/arpa/install_generator.rb
arpa-0.0.7 lib/generators/arpa/install_generator.rb