Sha256: e79e5d90b8524c587435706e1f4018f6dfc2f5352a27f531d40a9d127fdec728

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'rails/generators'
require 'rails/generators/migration'

class ActsAsFavoritorGenerator < Rails::Generators::Base
  include Rails::Generators::Migration

  source_root(File.join(File.dirname(__FILE__), 'templates'))
  desc 'Install acts_as_favoritor'

  def self.next_migration_number(dirname)
    if ActiveRecord::Base.timestamped_migrations
      Time.now.utc.strftime('%Y%m%d%H%M%S')
    else
      format('%<migration_number>.3d',
             migration_number: current_migration_number(dirname) + 1)
    end
  end

  def create_initializer
    template 'initializer.rb', 'config/initializers/acts_as_favoritor.rb'
  end

  def create_migration_file
    migration_template(
      'migration.rb.erb',
      'db/migrate/acts_as_favoritor_migration.rb',
      migration_version: migration_version
    )
  end

  def create_model
    template 'model.rb', 'app/models/favorite.rb'
  end

  private

  def migration_version
    return unless Rails.version >= '5.0.0'

    "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
acts_as_favoritor-6.0.1 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-6.0.0 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-5.0.3 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-5.0.2 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-5.0.1 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-5.0.0 lib/generators/acts_as_favoritor_generator.rb
acts_as_favoritor-4.0.3 lib/generators/acts_as_favoritor_generator.rb