Class: Zm::Client::Base::AdminObjectsCollection

Inherits:
ObjectsCollection show all
Defined in:
lib/zm/client/base/admin_objects_collection.rb

Overview

Collection AdminObjectsCollection

Constant Summary

Constants inherited from ObjectsCollection

ObjectsCollection::METHODS_MISSING_LIST

Instance Attribute Summary

Attributes inherited from ObjectsCollection

#parent

Instance Method Summary collapse

Methods inherited from ObjectsCollection

#all, #all!, #find, #first, #logger, #method_missing, #new, #order, #page, #per_page, #respond_to_missing?

Methods included from Inspector

#inspect, #instance_variables_map, #to_h, #to_s

Constructor Details

#initialize(parent) ⇒ AdminObjectsCollection

Returns a new instance of AdminObjectsCollection.



8
9
10
11
12
# File 'lib/zm/client/base/admin_objects_collection.rb', line 8

def initialize(parent)
  @parent = parent
  @persistent = false
  reset_query_params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zm::Client::Base::ObjectsCollection

Instance Method Details

#attrs(*attrs) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zm/client/base/admin_objects_collection.rb', line 39

def attrs(*attrs)
  attrs.map!(&:to_s)
  attrs.map!(&:strip)
  attrs.sort!
  attrs.uniq!
  attrs.delete_if { |attr| attr.nil? || attr.empty? }

  return self if @attrs == attrs

  @all = nil
  @attrs = attrs
  self
end

#clearObject



61
62
63
64
65
66
# File 'lib/zm/client/base/admin_objects_collection.rb', line 61

def clear
  @all = nil
  ldap_filter.clear
  reset_query_params
  self
end

#countObject



53
54
55
56
57
58
59
# File 'lib/zm/client/base/admin_objects_collection.rb', line 53

def count
  reset_query_params
  @count_only = SoapUtils::ON
  json = make_query
  @count_only = SoapUtils::OFF
  json[:SearchDirectoryResponse][:num]
end

#find_by(hash) ⇒ Object



14
15
16
17
18
19
# File 'lib/zm/client/base/admin_objects_collection.rb', line 14

def find_by(hash)
  item = find_in_cache(hash)
  return item unless item.nil?

  find_by!(hash)
end

#find_by_or_nil(hash, error_handler = SoapError) ⇒ Object



21
22
23
24
25
# File 'lib/zm/client/base/admin_objects_collection.rb', line 21

def find_by_or_nil(hash, error_handler = SoapError)
  find_by(hash)
rescue error_handler => _e
  nil
end

#find_each(offset: 0, limit: 1_000, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/zm/client/base/admin_objects_collection.rb', line 68

def find_each(offset: 0, limit: 1_000, &block)
  previous_persistent = @persistent.dup
  @persistent = true

  _attrs = @attrs
  total = count
  @attrs = _attrs

  @offset = offset
  @limit = limit

  while @offset < total
    build_response.each { |item| block.call(item) }
    @offset += @limit
  end

  ldap_filter.clear
  reset_query_params

  @persistent = previous_persistent
end

#ldapObject



27
28
29
30
31
# File 'lib/zm/client/base/admin_objects_collection.rb', line 27

def ldap
  @all = nil
  @apply_cos = SoapUtils::OFF
  self
end

#where(ldap_query) ⇒ Object



33
34
35
36
37
# File 'lib/zm/client/base/admin_objects_collection.rb', line 33

def where(ldap_query)
  @all = nil if ldap_filter.add(ldap_query)

  self
end