Sha256: d91653fca019941af9cdd14dd3c6312081bb365e2e196811e3e074f75db75c2f

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

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

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

  class_option :migrate_data, type: :boolean, default: false

  desc 'Creates migration files required by the active_recall spaced repetition gem.'

  source_paths << File.join(File.dirname(__FILE__), 'templates')

  def self.next_migration_number(path)
    ActiveRecord::Generators::Base.next_migration_number(path)
  end

  def create_migration_files
    create_migration_file_if_not_exist 'create_active_recall_tables'
    create_migration_file_if_not_exist 'add_active_recall_item_answer_counts'
    create_migration_file_if_not_exist 'migrate_okubo_to_active_recall' if options['migrate_data']
  end

  private

  def create_migration_file_if_not_exist(file_name)
    unless self.class.migration_exists?(File.dirname(File.expand_path("db/migrate/#{file_name}")), file_name)
      migration_template "#{file_name}.rb", "db/migrate/#{file_name}.rb"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_recall-1.6.4 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.6.3 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.6.2 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.6.1 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.6.0 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.5.0 lib/generators/active_recall/active_recall_generator.rb
active_recall-1.4.0 lib/generators/active_recall/active_recall_generator.rb