Class: Zm::Client::Base::ObjectsCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/base/objects_collection.rb

Overview

Abstract Class Collection

Constant Summary collapse

METHODS_MISSING_LIST =
i[select each map length].to_set.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/zm/client/base/objects_collection.rb', line 87

def method_missing(method, *args, &block)
  if METHODS_MISSING_LIST.include?(method)
    build_response.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



10
11
12
# File 'lib/zm/client/base/objects_collection.rb', line 10

def parent
  @parent
end

Instance Method Details

#allObject



33
34
35
# File 'lib/zm/client/base/objects_collection.rb', line 33

def all
  @all || all!
end

#all!Object



37
38
39
# File 'lib/zm/client/base/objects_collection.rb', line 37

def all!
  @all = build_response
end

#attrs(*attrs) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/zm/client/base/objects_collection.rb', line 79

def attrs(*attrs)
  return self if @attrs == attrs

  @all = nil
  @attrs = attrs
  self
end

#build_from_entry(entry) ⇒ Object



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

def build_from_entry(entry)
  child = @child_class.new(@parent)
  child.init_from_json(entry)
  child
end

#countObject



74
75
76
77
# File 'lib/zm/client/base/objects_collection.rb', line 74

def count
  @count_only = SoapUtils::ON
  make_query[:Body][:SearchDirectoryResponse][:num]
end

#find(id) ⇒ Object



18
19
20
# File 'lib/zm/client/base/objects_collection.rb', line 18

def find(id)
  find_by(id: id)
end

#firstObject



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

def first
  @limit = 1
  build_response.first
end

#new {|child| ... } ⇒ Object

Yields:

  • (child)


12
13
14
15
16
# File 'lib/zm/client/base/objects_collection.rb', line 12

def new
  child = @child_class.new(@parent)
  yield(child) if block_given?
  child
end

#order(sort_by, sort_ascending = SoapUtils::ON) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/zm/client/base/objects_collection.rb', line 65

def order(sort_by, sort_ascending = SoapUtils::ON)
  return self if @sort_by == sort_by && @sort_ascending == sort_ascending

  @all = nil
  @sort_by = sort_by
  @sort_ascending = sort_ascending
  self
end

#page(offset) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/zm/client/base/objects_collection.rb', line 57

def page(offset)
  return self if @offset == offset

  @all = nil
  @offset = offset
  self
end

#per_page(limit) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/zm/client/base/objects_collection.rb', line 49

def per_page(limit)
  return self if @limit == limit

  @all = nil
  @limit = limit
  self
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/zm/client/base/objects_collection.rb', line 95

def respond_to_missing?(method, *)
  METHODS_MISSING_LIST.include?(method) || super
end

#where(ldap_query) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/zm/client/base/objects_collection.rb', line 41

def where(ldap_query)
  return self if @ldap_query == ldap_query

  @all = nil
  @ldap_query = ldap_query
  self
end