Class: ProxES::User
- Inherits:
-
Base
show all
- Defined in:
- lib/proxes/models/user.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/proxes/models/user.rb', line 20
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s[-1] == '?'
role?(method_sym[0..-2])
else
super
end
end
|
Instance Method Details
#after_create ⇒ Object
Add the basic roles and identity
45
46
47
|
# File 'lib/proxes/models/user.rb', line 45
def after_create
check_roles
end
|
#check_roles ⇒ Object
49
50
51
52
|
# File 'lib/proxes/models/user.rb', line 49
def check_roles
add_role Role.find_or_create(name: 'user') unless role?('user')
add_role Role.find_or_create(name: 'super_admin') if id == 1 && ENV['RACK_ENV'] != 'test' && !role?('super_admin')
end
|
#gravatar ⇒ Object
32
33
34
35
|
# File 'lib/proxes/models/user.rb', line 32
def gravatar
hash = Digest::MD5.hexdigest(email.downcase)
"https://www.gravatar.com/avatar/#{hash}"
end
|
#index_prefix ⇒ Object
54
55
56
|
# File 'lib/proxes/models/user.rb', line 54
def index_prefix
email
end
|
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
28
29
30
|
# File 'lib/proxes/models/user.rb', line 28
def respond_to_missing?(name, _include_private = false)
name[-1] == '?'
end
|
#role?(check) ⇒ Boolean
16
17
18
|
# File 'lib/proxes/models/user.rb', line 16
def role?(check)
!roles_dataset.first(name: check).nil?
end
|
#username ⇒ Object
58
59
60
|
# File 'lib/proxes/models/user.rb', line 58
def username
identity_dataset.first.username
end
|
#validate ⇒ Object
37
38
39
40
41
42
|
# File 'lib/proxes/models/user.rb', line 37
def validate
validates_presence :email
return if email.blank?
validates_unique :email
validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :email)
end
|