Class: ActiveZuora::CollectionProxy

Inherits:
Object
  • Object
show all
Includes:
BatchSubscribe, ZObject, Enumerable
Defined in:
lib/active_zuora/collection_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BatchSubscribe

#batch_subscribe, #batch_subscribe!

Methods included from ZObject

#==

Constructor Details

#initialize(ary = []) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.



10
11
12
13
14
15
16
17
# File 'lib/active_zuora/collection_proxy.rb', line 10

def initialize(ary = [])
  unless ary.empty?
    raise "objects in collection must be ActiveZuora object instances" unless class_names = ary.map{|object| object.zuora_object_name}.uniq
    raise "objects in collection must be ActiveZuora object instances of the same class" unless class_names.length == 1
    @zobject_class = class_names.first
  end
  @records = ary
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



8
9
10
# File 'lib/active_zuora/collection_proxy.rb', line 8

def records
  @records
end

#zobject_classObject (readonly)

Returns the value of attribute zobject_class.



8
9
10
# File 'lib/active_zuora/collection_proxy.rb', line 8

def zobject_class
  @zobject_class
end

Instance Method Details

#add(object) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/active_zuora/collection_proxy.rb', line 19

def add object
  raise "object must be an ActiveZuora object instance" unless object.zuora_object_name
  if records.empty?
    @zobject_class = object.zuora_object_name
  else
    raise "object must be must be ActiveZuora object instances of the same class as other elements in the Collection" unless object.zuora_object_name == zobject_class
  end
  @records.push object
end

#eachObject



29
30
31
# File 'lib/active_zuora/collection_proxy.rb', line 29

def each
  records.each { |r| yield r }
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_zuora/collection_proxy.rb', line 33

def empty?
  records.empty?
end