Sha256: 5c7a5ae71288a33a6b55a8082c0b4de44e66ed80c29cb456bcd51865050b84ca

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

require 'rails/generators/active_record'

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

      source_root File.expand_path('../templates', __dir__)

      def inject_secrets
        insert_into_file 'config/secrets.yml', secrets_template,
                         after: "bugsnag_api_key: <%= Figaro.env.bugsnag_api_key! %>\n"
      end

      def copy_migration
        migration_template 'migration.rb', 'db/migrate/create_users.rb'
      end

      def copy_model
        template 'user.rb', 'app/models/user.rb'
      end

      def inject_routes
        insert_into_file 'config/routes.rb', routes_template,
                         after: "Rails.application.routes.draw do\n"
      end

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

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

      private

      def routes_template
        <<RUBY
  devise_for :users, controllers: {
    omniauth_callbacks: 'infinum_id/users/omniauth_callbacks'
  }
RUBY
      end

      def secrets_template
<<RUBY
  infinum_id:
    client_id: <%= Figaro.env.infinum_id_client_id %>
    client_secret: <%= Figaro.env.infinum_id_client_secret %>
    url: <%= Figaro.env.infinum_id_client_url %>
RUBY
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
infinum_id-2.2.0 lib/generators/infinum_id/install_generator.rb
infinum_id-2.1.0 lib/generators/infinum_id/install_generator.rb
infinum_id-2.0.1 lib/generators/infinum_id/install_generator.rb
infinum_id-2.0.0 lib/generators/infinum_id/install_generator.rb
infinum_id-1.6.0 lib/generators/infinum_id/install_generator.rb
infinum_id-1.5.1 lib/generators/infinum_id/install_generator.rb
infinum_id-1.5.0 lib/generators/infinum_id/install_generator.rb