Class: DeviseJwtAuth::InstallMongoidGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
InstallGeneratorHelpers
Defined in:
lib/generators/devise_jwt_auth/install_mongoid_generator.rb

Overview

Adds Mongoid settings to ORM

Instance Method Summary collapse

Methods included from InstallGeneratorHelpers

included

Instance Method Details

#create_user_modelObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/devise_jwt_auth/install_mongoid_generator.rb', line 10

def create_user_model
  fname = "app/models/#{user_class.underscore}.rb"
  if File.exist?(File.join(destination_root, fname))
    inclusion = 'include DeviseJwtAuth::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 DeviseJwtAuth::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