Sha256: 5c4cbf0b8ad7a152a4debe1ef55e0ef3337d2db93e3ac047e3e80dce6558518c

Contents?: true

Size: 1001 Bytes

Versions: 4

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators/migration'

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

    desc 'Generates migration for contactable (address 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 'address_migration.erb', 'db/migrate/acts_as_contactable_address_migration.rb', migration_version: migration_version
      end
    end

    private

    def migration_version
      '[4.2]' if rails5?
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts-as-contactable-0.2.2 lib/generators/acts_as_contactable/migration/migration_generator.rb
acts-as-contactable-0.2.1 lib/generators/acts_as_contactable/migration/migration_generator.rb
acts-as-contactable-0.2.0 lib/generators/acts_as_contactable/migration/migration_generator.rb
acts-as-contactable-0.1.10 lib/generators/acts_as_contactable/migration/migration_generator.rb