Sha256: 6d82078b038502f238c3dd46141cc0e6d67901e0a25bb0c9565e22f322d99f4b

Contents?: true

Size: 1.26 KB

Versions: 18

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require "rails/generators/base"
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"
        template "app/models/oauth_token.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

18 entries across 18 versions & 1 rubygems

Version Path
rodauth-oauth-0.7.2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.7.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.7.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.6.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.6.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.5.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.5.0 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.4.3 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.4.2 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.4.1 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.4.0 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.3.0 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.2.0 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.1.0 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.0.6 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.0.5 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.0.4 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.0.3 lib/generators/roda/oauth/install_generator.rb