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?

Methods included from AttributesClass

#define_attr, #model_name

Methods included from Attributes

#attribute, #attributes, #attributes=, #clear_attribute

Constructor Details

This class inherits a constructor from RHC::Rest::Base

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

Returns:

  • (Boolean)


11
12
13
# File 'lib/rhc/rest/membership.rb', line 11

def admin?
  role == 'admin'
end

#editor?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rhc/rest/membership.rb', line 15

def editor?
  role == 'edit'
end

#explicit_role?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rhc/rest/membership.rb', line 35

def explicit_role?
  explicit_role.present?
end

#fromObject



39
40
41
# File 'lib/rhc/rest/membership.rb', line 39

def from
  Array(attributes['from'])
end

#grant_from?(type, id) ⇒ Boolean

Returns:

  • (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

#nameObject



27
28
29
# File 'lib/rhc/rest/membership.rb', line 27

def name
  attributes['name'] || 
end

#owner?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rhc/rest/membership.rb', line 7

def owner?
  !!owner
end

#role_weightObject



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

Returns:

  • (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

#to_sObject



52
53
54
55
56
57
58
59
60
# File 'lib/rhc/rest/membership.rb', line 52

def to_s
  if name == 
    "#{} (#{role})"
  elsif 
    "#{name} <#{}> (#{role})"
  else
    "#{name} (#{role})"
  end
end

#typeObject



31
32
33
# File 'lib/rhc/rest/membership.rb', line 31

def type
  attributes['type'] || 'user'
end

#viewer?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rhc/rest/membership.rb', line 19

def viewer?
  role == 'view'
end