Sha256: 389801110851ddda447712b81485a640ae49f6d383634e61ed861ec5c76600fe

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

require 'rails/generators'
require "rails/generators/active_record"

# This generator adds a migration for the {FriendlyId::History
# FriendlyId::History} addon.
class FriendlyIdGenerator < ActiveRecord::Generators::Base
  # ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase which requires a NAME parameter for the
  # new table name. Our generator always uses 'friendly_id_slugs', so we just set a random name here.
  argument :name, type: :string, default: 'random_name'

  class_option :'skip-migration', :type => :boolean, :desc => "Don't generate a migration for the slugs table"
  class_option :'skip-initializer', :type => :boolean, :desc => "Don't generate an initializer"

  source_root File.expand_path('../../friendly_id', __FILE__)

  # Copies the migration template to db/migrate.
  def copy_files
    return if options['skip-migration']
    migration_template 'migration.rb', 'db/migrate/create_friendly_id_slugs.rb'
  end

  def create_initializer
    return if options['skip-initializer']
    copy_file 'initializer.rb', 'config/initializers/friendly_id.rb'
  end
end

Version data entries

27 entries across 27 versions & 3 rubygems

Version Path
friendly_id-5.0.2 lib/generators/friendly_id_generator.rb
friendly_id-5.0.1 lib/generators/friendly_id_generator.rb
friendly_id-5.0.0 lib/generators/friendly_id_generator.rb
friendly_id-5.0.0.rc3 lib/generators/friendly_id_generator.rb
friendly_id-5.0.0.rc2 lib/generators/friendly_id_generator.rb
friendly_id-5.0.0.rc1 lib/generators/friendly_id_generator.rb
friendly_id-5.0.0.beta4 lib/generators/friendly_id_generator.rb