Sha256: 9ad4dfb596ab01e96650936d89c840d692218f9e10c374bee9df727bb7e6451c

Contents?: true

Size: 702 Bytes

Versions: 8

Compression:

Stored size: 702 Bytes

Contents

require 'rails/generators/base'
require 'rails/generators/active_record'
class SlugMigrationGenerator < Rails::Generators::Base
  include ActiveRecord::Generators::Migration

  source_root File.expand_path('../templates', __FILE__)
  argument :slugged_model, type: :string, required: true
  class_option :slug_name, type: :string, default: 'slug'

  def create_migration_file
    migration_template "slug_migration.rb", "db/migrate/add_slug_to_#{slugged_model_table}.rb"
  end

  private

  def slugged_model_table
    slugged_model.underscore.pluralize
  end

  def slugged_model_class_name
    slugged_model.camelcase
  end

  def slug_column_name
    options.fetch("slug_name").underscore
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
human_urls-0.1.7.pre.alpha.0 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.6.pre.alpha.0 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.5.pre.alpha.0 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.4.pre.alpha.0 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.3.pre.alpha.0 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.2 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.1 lib/generators/slug_migration/slug_migration_generator.rb
human_urls-0.1.0 lib/generators/slug_migration/slug_migration_generator.rb