Module: Devise::Models::Approvable

Defined in:
lib/devise_approvable/model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/devise_approvable/model.rb', line 5

def self.included(base)
  puts "Devise::Models::Approvable module injected into #{self.class} class"

  base.class_eval do
    extend ClassMethods

    before_create :generate_approval_token, :if => :approval_required?
    after_create  :send_approval_instructions, :unless => :approved?
  end
end

Instance Method Details

#active_for_authentication?Boolean

override

Returns:

  • (Boolean)


17
18
19
# File 'lib/devise_approvable/model.rb', line 17

def active_for_authentication? 
    super && approved? 
end

#approve!Object



31
32
33
34
35
# File 'lib/devise_approvable/model.rb', line 31

def approve!
  self.approved_at = Time.now.utc
  self.approval_token = nil
  save(:validate => false)
end

#approved?Boolean

Verifies whether a user is confirmed or not

Returns:

  • (Boolean)


38
39
40
# File 'lib/devise_approvable/model.rb', line 38

def approved?
  !!self.approved_at
end

#inactive_messageObject

override



22
23
24
25
26
27
28
# File 'lib/devise_approvable/model.rb', line 22

def inactive_message 
  if !approved? 
    :not_approved 
  else 
    super # Use whatever other message 
  end 
end

#send_approval_instructionsObject

Send approval instructions by email



48
49
50
51
52
53
54
55
# File 'lib/devise_approvable/model.rb', line 48

def send_approval_instructions
  unless @raw_approval_token
    generate_approval_token!
  end
  
  opts = { to: self.class.admin_email }
  send_devise_notification(:approval_instructions, @raw_approval_token, opts)
end

#skip_approval!Object



42
43
44
45
# File 'lib/devise_approvable/model.rb', line 42

def skip_approval!
  self.approved_at = Time.now.utc
  @skip_approval = true
end