Class: Five9::User
- Inherits:
-
Object
show all
- Defined in:
- lib/five9/user.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ User
Returns a new instance of User.
4
5
6
7
8
9
|
# File 'lib/five9/user.rb', line 4
def initialize(args)
@user_info = args.make_accessible
@general_info = @user_info[:general_info].make_accessible
@roles = @user_info[:roles].make_accessible
@skills = SkillArray.new(args[:skills])
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
45
46
47
|
# File 'lib/five9/user.rb', line 45
def method_missing(method_name, *args)
@general_info.send(method_name, *args)
end
|
Instance Attribute Details
#general_info ⇒ Object
Returns the value of attribute general_info.
3
4
5
|
# File 'lib/five9/user.rb', line 3
def general_info
@general_info
end
|
#roles ⇒ Object
Returns the value of attribute roles.
3
4
5
|
# File 'lib/five9/user.rb', line 3
def roles
@roles
end
|
#skills ⇒ Object
Returns the value of attribute skills.
3
4
5
|
# File 'lib/five9/user.rb', line 3
def skills
@skills
end
|
Class Method Details
.all ⇒ Object
61
62
63
64
65
|
# File 'lib/five9/user.rb', line 61
def self.all
UserManagement.get_users_info.map do |user_info|
new(user_info)
end
end
|
.create!(args) ⇒ Object
53
54
55
|
# File 'lib/five9/user.rb', line 53
def self.create!(args)
new UserManagement.create_user(args)
end
|
.exist?(username) ⇒ Boolean
49
50
51
|
# File 'lib/five9/user.rb', line 49
def self.exist?(username)
not UserManagement.get_users_info(username)[:general_info].nil?
end
|
.find(username) ⇒ Object
57
58
59
|
# File 'lib/five9/user.rb', line 57
def self.find(username)
new(UserManagement.get_users_info(username)) if exist?(username)
end
|
.where(args) ⇒ Object
67
68
69
70
71
|
# File 'lib/five9/user.rb', line 67
def self.where(args)
all.keep_if do |user|
user.merge(args).to_hash == user.to_hash
end
end
|
Instance Method Details
#delete! ⇒ Object
24
25
26
|
# File 'lib/five9/user.rb', line 24
def delete!
UserManagement.delete_user user_name
end
|
#save ⇒ Object
18
19
20
21
22
|
# File 'lib/five9/user.rb', line 18
def save
UserManagement.modify_user(build_modify_hash)
@skills.update!
self
end
|
#to_h ⇒ Object
11
12
13
14
15
16
|
# File 'lib/five9/user.rb', line 11
def to_h
@user_info[:general_info] = @general_info
@user_info[:roles] = @roles
@user_info[:skills] = @skills.to_a
@user_info
end
|
#update(args) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/five9/user.rb', line 28
def update(args)
if args[:general_info]
@user_info = to_h.merge(args)
@general_info = @user_info[:general_info].make_accessible
@roles = @user_info[:roles].make_accessible
@skills = SkillArray.new(args[:skills])
@user_info
else
merge! args
end
end
|
#update!(args) ⇒ Object
40
41
42
43
|
# File 'lib/five9/user.rb', line 40
def update!(args)
update args
save
end
|