Sha256: 42342326c0cac434dc0e68031eb4018970c799e12d4bdc621c2c6f5b1037d27b

Contents?: true

Size: 1.35 KB

Versions: 7

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 and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :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

7 entries across 7 versions & 4 rubygems

Version Path
devise-tokens-1.0.4 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.3 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.2 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.1 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth-1.1.0 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth_fork_dfabarbosa-1.0.0 lib/generators/devise_token_auth/install_mongoid_generator.rb
devise_token_auth_skycocker_fork-1.0.0 lib/generators/devise_token_auth/install_mongoid_generator.rb