Sha256: 5e2673e6f6a28381cda31af33352580e7baaa9a4c815926efe7d1fe184434094

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require "rails/generators"
require "rails/generators/migration"
require "rails/generators/active_record"

module Rodauth::OAuth::Rails
  module Generators
    class InstallGenerator < ::Rails::Generators::Base
      include ::Rails::Generators::Migration

      source_root "#{__dir__}/templates"
      namespace "rodauth:oauth:install"

      def create_rodauth_migration
        return unless defined?(ActiveRecord::Base)

        migration_template "db/migrate/create_rodauth_oauth.rb", "db/migrate/create_rodauth_oauth.rb"
      end

      def create_oauth_models
        return unless defined?(ActiveRecord::Base)

        template "app/models/oauth_application.rb"
        template "app/models/oauth_grant.rb"
      end

      private

      # required by #migration_template action
      def self.next_migration_number(dirname)
        ActiveRecord::Generators::Base.next_migration_number(dirname)
      end

      def migration_version
        if ActiveRecord.version >= Gem::Version.new("5.0.0")
          "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
        end
      end

      def adapter
        ActiveRecord::Base.connection_config.fetch(:adapter)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rodauth-oauth-1.6.3 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.6.2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.6.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.5.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.4.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.3.2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.3.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.3.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.2.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.1.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.0.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.0.0.pre.beta2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-1.0.0.pre.beta1 lib/generators/rodauth/oauth/install_generator.rb