Class: RHC::Rest::Membership::Member
- Inherits:
-
Base
show all
- Defined in:
- lib/rhc/rest/membership.rb
Instance Method Summary
collapse
Methods inherited from Base
#add_message, #has_param?, #initialize, #link_href, #links, #rest_method, #supports?
#define_attr, #model_name
Methods included from Attributes
#attribute, #attributes, #attributes=, #clear_attribute
Instance Method Details
#<=>(other) ⇒ Object
62
63
64
|
# File 'lib/rhc/rest/membership.rb', line 62
def <=>(other)
[role_weight, type, name, id] <=> [other.role_weight, other.type, other.name, other.id]
end
|
#admin? ⇒ Boolean
11
12
13
|
# File 'lib/rhc/rest/membership.rb', line 11
def admin?
role == 'admin'
end
|
#editor? ⇒ Boolean
15
16
17
|
# File 'lib/rhc/rest/membership.rb', line 15
def editor?
role == 'edit'
end
|
#explicit_role? ⇒ Boolean
35
36
37
|
# File 'lib/rhc/rest/membership.rb', line 35
def explicit_role?
explicit_role.present?
end
|
39
40
41
|
# File 'lib/rhc/rest/membership.rb', line 39
def from
Array(attributes['from'])
end
|
#grant_from?(type, id) ⇒ Boolean
43
44
45
|
# File 'lib/rhc/rest/membership.rb', line 43
def grant_from?(type, id)
from.detect {|f| f['type'] == type && f['id'] == id}
end
|
27
28
29
|
# File 'lib/rhc/rest/membership.rb', line 27
def name
attributes['name'] || login
end
|
#owner? ⇒ Boolean
7
8
9
|
# File 'lib/rhc/rest/membership.rb', line 7
def owner?
!!owner
end
|
#role_weight ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/rhc/rest/membership.rb', line 66
def role_weight
if owner?
0
else
case role
when 'admin' then 1
when 'edit' then 2
when 'view' then 3
else 4
end
end
end
|
#team? ⇒ Boolean
23
24
25
|
# File 'lib/rhc/rest/membership.rb', line 23
def team?
type == 'team'
end
|
#teams(members) ⇒ Object
47
48
49
50
|
# File 'lib/rhc/rest/membership.rb', line 47
def teams(members)
team_ids = from.inject([]) {|ids, f| ids << f['id'] if f['type'] == 'team'; ids }
members.select {|m| m.team? && team_ids.include?(m.id) }
end
|
52
53
54
55
56
57
58
59
60
|
# File 'lib/rhc/rest/membership.rb', line 52
def to_s
if name == login
"#{login} (#{role})"
elsif login
"#{name} <#{login}> (#{role})"
else
"#{name} (#{role})"
end
end
|
31
32
33
|
# File 'lib/rhc/rest/membership.rb', line 31
def type
attributes['type'] || 'user'
end
|
#viewer? ⇒ Boolean
19
20
21
|
# File 'lib/rhc/rest/membership.rb', line 19
def viewer?
role == 'view'
end
|