Sha256: 77fc1af50988ffcc4af1e1903d13e03557f4f9fe861e07517ce7ecc07f35a313

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

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

module NotificationHandler
  class InstallGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    source_root(File.join(File.dirname(__FILE__), '../templates/install'))
    desc 'Install NotificationHandler'

    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/notification_handler.rb'
    end

    def create_notifications_migration_file
      migration_template(
        'notifications_migration.rb.erb',
        'db/migrate/notification_handler_migration.rb',
        migration_version: migration_version
      )
    end

    def create_notification_model
      template 'notification_model.rb', 'app/models/notification.rb'
    end

    private

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notification-handler-3.0.2 lib/generators/notification_handler/install_generator.rb