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



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.



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

#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

#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

#loggerObject



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

def logger
  @parent.logger
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



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



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

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

  @all = nil
  @offset = offset
  self
end

#per_page(limit) ⇒ Object



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

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