Class: ProxES::User
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- ProxES::User
show all
- Includes:
- Base
- Defined in:
- lib/proxes/models/user.rb
Instance Method Summary
collapse
Methods included from Base
#for_json
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/proxes/models/user.rb', line 22
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
47
48
49
|
# File 'lib/proxes/models/user.rb', line 47
def after_create
check_roles
end
|
#check_roles ⇒ Object
51
52
53
54
|
# File 'lib/proxes/models/user.rb', line 51
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
34
35
36
37
|
# File 'lib/proxes/models/user.rb', line 34
def gravatar
hash = Digest::MD5.hexdigest(email.downcase)
"https://www.gravatar.com/avatar/#{hash}"
end
|
#index_prefix ⇒ Object
56
57
58
|
# File 'lib/proxes/models/user.rb', line 56
def index_prefix
email
end
|
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/proxes/models/user.rb', line 30
def respond_to_missing?(name, _include_private = false)
name[-1] == '?'
end
|
#role?(check) ⇒ Boolean
18
19
20
|
# File 'lib/proxes/models/user.rb', line 18
def role?(check)
!roles_dataset.first(name: check).nil?
end
|
#username ⇒ Object
60
61
62
|
# File 'lib/proxes/models/user.rb', line 60
def username
identity_dataset.first.username
end
|
#validate ⇒ Object
39
40
41
42
43
44
|
# File 'lib/proxes/models/user.rb', line 39
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
|