Sha256: 8c8bfc50541a03bfcfb8f5591628f5ac59b1b542ffc33b03daf729da49268c52

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

# frozen_string_literal: true

require 'rails/generators/active_record'

module Devise
  module Generators
    class AcquirableGenerator < ActiveRecord::Generators::Base
      source_root File.expand_path('templates', __dir__)

      desc 'Generate migration for ActiveRecord and add :acquirable directive in the given model.'

      def copy_migration
        migration_template 'migration.rb', "db/migrate/devise_acquirable_add_to_#{table_name}.rb",
                           migration_version: migration_version
      end

      def inject_devise_acquirable_content
        path = File.join('app', 'models', "#{file_path}.rb")
        inject_into_file(path, 'acquirable, :', after: 'devise :') if File.exist?(path)
      end

      private

      def versioned_migrations?
        Rails::VERSION::MAJOR >= 5
      end

      def migration_version
        "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if versioned_migrations?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise-acquirable-0.1.1 lib/generators/devise/acquirable_generator.rb