Module: RHC::Rest::Membership

Included in:
Application, Domain, Team
Defined in:
lib/rhc/rest/membership.rb

Defined Under Namespace

Classes: Member

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



80
81
# File 'lib/rhc/rest/membership.rb', line 80

def self.included(other)
end

Instance Method Details

#compact_membersObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rhc/rest/membership.rb', line 106

def compact_members
  arr = members.reject(&:owner?) rescue []
  if arr.length > 5
    arr = arr.sort_by(&:name)
    admin, arr = arr.partition(&:admin?)
    edit, arr = arr.partition(&:editor?)
    view, arr = arr.partition(&:viewer?)
    admin << "Admins" if admin.present?
    edit << "Editors" if edit.present?
    view << "Viewers" if view.present?
    arr.map!(&:to_s)
    admin.concat(edit).concat(view).concat(arr)
  elsif arr.present?
    arr.sort_by{ |m| [m.role_weight, m.name] }.join(', ')
  end
end

#default_member_roleObject



91
92
93
# File 'lib/rhc/rest/membership.rb', line 91

def default_member_role
  'edit'
end

#delete_members(options = {}) ⇒ Object



130
131
132
133
134
135
# File 'lib/rhc/rest/membership.rb', line 130

def delete_members(options={})
  raise RHC::MembersNotSupported unless supports_members?
  rest_method "LIST_MEMBERS", nil, {:method => :delete}.merge(options)
ensure
  @members = attributes['members'] = nil
end

#leave(options = {}) ⇒ Object



137
138
139
140
141
142
# File 'lib/rhc/rest/membership.rb', line 137

def leave(options={})
  raise RHC::MembersNotSupported.new("The server does not support leaving this resource.") unless supports? 'LEAVE'
  rest_method "LEAVE", nil, options
ensure
  @members = attributes['members'] = nil
end

#membersObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/rhc/rest/membership.rb', line 95

def members
  @members ||=
    if (members = attributes['members']).nil?
      debug "Getting all members for #{id}"
      raise RHC::MembersNotSupported unless supports_members?
      rest_method 'LIST_MEMBERS'
    else
      members.map{ |m| Member.new(m, client) }
    end
end

#ownerObject



144
145
146
147
148
# File 'lib/rhc/rest/membership.rb', line 144

def owner
  if o = Array(attributes['members']).find{ |m| m['owner'] == true }
    o['name'] || o['login']
  end
end

#supports_members?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/rhc/rest/membership.rb', line 83

def supports_members?
  supports? 'LIST_MEMBERS'
end

#supports_update_members?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/rhc/rest/membership.rb', line 87

def supports_update_members?
  supports? 'UPDATE_MEMBERS'
end

#update_members(members, options = {}) ⇒ Object



123
124
125
126
127
128
# File 'lib/rhc/rest/membership.rb', line 123

def update_members(members, options={})
  raise "Members must be an array" unless members.is_a?(Array)
  raise RHC::MembersNotSupported unless supports_members?
  raise RHC::ChangeMembersOnResourceNotSupported unless supports_update_members?
  @members = (attributes['members'] = rest_method('UPDATE_MEMBERS', {:members => members}, options))
end