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
19
20
21
22
23
24
25
|
# File 'lib/proxes/models/user.rb', line 19
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
44
45
46
|
# File 'lib/proxes/models/user.rb', line 44
def after_create
check_roles
end
|
#check_roles ⇒ Object
48
49
50
51
|
# File 'lib/proxes/models/user.rb', line 48
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
31
32
33
34
|
# File 'lib/proxes/models/user.rb', line 31
def gravatar
hash = Digest::MD5.hexdigest(email.downcase)
"https://www.gravatar.com/avatar/#{hash}"
end
|
#index_prefix ⇒ Object
53
54
55
|
# File 'lib/proxes/models/user.rb', line 53
def index_prefix
email
end
|
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
27
28
29
|
# File 'lib/proxes/models/user.rb', line 27
def respond_to_missing?(name, _include_private = false)
name[-1] == '?'
end
|
#role?(check) ⇒ Boolean
15
16
17
|
# File 'lib/proxes/models/user.rb', line 15
def role?(check)
!roles_dataset.first(name: check).nil?
end
|
#username ⇒ Object
57
58
59
|
# File 'lib/proxes/models/user.rb', line 57
def username
identity_dataset.first.username
end
|
#validate ⇒ Object
36
37
38
39
40
41
|
# File 'lib/proxes/models/user.rb', line 36
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
|