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

Inherits:
Object
  • Object
show all
Includes:
Inspector
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

Methods included from Inspector

#inspect, #instance_variables_map, #to_h, #to_s

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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.



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

def parent
  @parent
end

Instance Method Details

#allObject



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

def all
  @all || all!
end

#all!Object



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

def all!
  @all = build_response
end

#find(id) ⇒ Object



20
21
22
# File 'lib/zm/client/base/objects_collection.rb', line 20

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

#firstObject



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

def first
  @limit = 1
  build_response.first
end

#loggerObject



78
79
80
# File 'lib/zm/client/base/objects_collection.rb', line 78

def logger
  @parent.logger
end

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

Yields:

  • (child)


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

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

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



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

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 Also known as: offset



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

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

  @all = nil
  @offset = offset
  self
end

#per_page(limit) ⇒ Object Also known as: limit



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

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

  @all = nil
  @limit = limit
  self
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


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

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