Sha256: 98f3fc210376ab33080ca44b19f3c15d48e3cb9ee3f3eb2ac58359610644262e

Contents?: true

Size: 1.26 KB

Versions: 2

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 "roda: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

2 entries across 2 versions & 1 rubygems

Version Path
rodauth-oauth-0.0.2 lib/generators/roda/oauth/install_generator.rb
rodauth-oauth-0.0.1 lib/generators/roda/oauth/install_generator.rb