Sha256: 258e4188e7a2657d46ecd529c0ffe2806fcee3e7a477eb01723485abf7cbfa1d

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require_relative 'install_generator_helpers'

module DeviseTokenAuth
  class InstallMongoidGenerator < Rails::Generators::Base
    include DeviseTokenAuth::InstallGeneratorHelpers

    def create_user_model
      fname = "app/models/#{user_class.underscore}.rb"
      if File.exist?(File.join(destination_root, fname))
        inclusion = 'include DeviseTokenAuth::Concerns::User'
        unless parse_file_for_line(fname, inclusion)
          inject_into_file fname, before: /end\s\z/ do <<-'RUBY'

  include Mongoid::Locker

  field :locker_locked_at, type: Time
  field :locker_locked_until, type: Time

  locker locked_at_field: :locker_locked_at,
         locked_until_field: :locker_locked_until

  ## Required
  field :provider, type: String
  field :uid,      type: String, default: ''

  ## Tokens
  field :tokens, type: Hash, default: {}

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  include DeviseTokenAuth::Concerns::User

  index({ uid: 1, provider: 1}, { name: 'uid_provider_index', unique: true, background: true })
            RUBY
          end
        end
      else
        template('user_mongoid.rb.erb', fname)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
devise_token_auth-1.2.4 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.2.2 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.2.1 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.2.0 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.5 lib/generators/devise_token_auth/install_mongoid_generator.rb
sidecar_token_auth-1.0.1 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.4 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth_multitenancy-1.1.3.2 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth_multitenancy-1.1.3.1 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth_multitenancy-1.1.3.alpha1 lib/generators/devise_token_auth/install_mongoid_generator.rb