Sha256: bfab3352bceaf5eadd337cd427b859f10887495fb9e8f16de74e5347baa98313

Contents?: true

Size: 1.26 KB

Versions: 12

Compression:

Stored size: 1.26 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"
        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

12 entries across 12 versions & 1 rubygems

Version Path
rodauth-oauth-0.10.4 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.10.3 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.10.2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.10.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.10.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.9.3 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.9.2 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.9.1 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.9.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.8.0 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.7.4 lib/generators/rodauth/oauth/install_generator.rb
rodauth-oauth-0.7.3 lib/generators/rodauth/oauth/install_generator.rb