Sha256: 620624db0ddc147371b26ba2efb023f23b5a0a2e33e408dfe9edf7d60870d72e

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require "rails/generators/migration"

module ActsAsVotable
  class MigrationGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    desc "Generates migration for votable (votes table)"

    def self.orm
      Rails::Generators.options[:rails][:orm]
    end

    def self.source_root
      File.join(File.dirname(__FILE__), "templates", (orm.to_s unless orm.class.eql?(String)))
    end

    def self.orm_has_migration?
      [:active_record].include? orm
    end

    def self.next_migration_number(_path)
      Time.now.utc.strftime("%Y%m%d%H%M%S")
    end

    def create_migration_file
      if self.class.orm_has_migration?
        migration_template "migration.erb", "db/migrate/acts_as_votable_migration.rb", migration_version: migration_version
      end
    end


    private

    def migration_version
      if rails5?
        "[4.2]"
      elsif rails6?
        "[6.0]"
      end
    end

    def rails5?
      Rails.version.start_with? "5"
    end

    def rails6?
      Rails.version.start_with? "6"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_votable-0.13.1 lib/generators/acts_as_votable/migration/migration_generator.rb
acts_as_votable-0.13.0 lib/generators/acts_as_votable/migration/migration_generator.rb
acts_as_votable-0.12.1 lib/generators/acts_as_votable/migration/migration_generator.rb