Class: Zm::Client::CosServersCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/cos/cos_servers_collection.rb

Overview

Collection Servers from cos

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ CosServersCollection

Returns a new instance of CosServersCollection.



7
8
9
# File 'lib/zm/client/cos/cos_servers_collection.rb', line 7

def initialize(parent)
  @parent = parent
end

Instance Method Details

#add!(*servers) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/zm/client/cos/cos_servers_collection.rb', line 21

def add!(*servers)
  server_ids = server_ids(servers)
  server_ids.delete_if { |id| @parent.zimbraMailHostPool.include?(id) }
  return false if server_ids.empty?

  payload = { zimbraMailHostPool: @parent.zimbraMailHostPool + server_ids }
  return false unless @parent.update!(payload)

  @parent.zimbraMailHostPool += server_ids
  true
end

#allObject



11
12
13
# File 'lib/zm/client/cos/cos_servers_collection.rb', line 11

def all
  @all || all!
end

#all!Object



15
16
17
18
19
# File 'lib/zm/client/cos/cos_servers_collection.rb', line 15

def all!
  @all = @parent.zimbraMailHostPool.map do |server_id|
    servers_collection.find_by(id: server_id)
  end
end

#remove!(*servers) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zm/client/cos/cos_servers_collection.rb', line 33

def remove!(*servers)
  server_ids = server_ids(servers)
  server_ids.delete_if { |id| !@parent.zimbraMailHostPool.include?(id) }
  return false if server_ids.empty?

  payload = { zimbraMailHostPool: @parent.zimbraMailHostPool - server_ids }
  return false unless @parent.update!(payload)

  @parent.zimbraMailHostPool += server_ids
  true
end