Class: ActiveZuora::CollectionProxy
- Inherits:
-
Object
- Object
- ActiveZuora::CollectionProxy
- Includes:
- BatchSubscribe, ZObject, Enumerable
- Defined in:
- lib/active_zuora/collection_proxy.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#zobject_class ⇒ Object
readonly
Returns the value of attribute zobject_class.
Instance Method Summary collapse
- #add(object) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(ary = []) ⇒ CollectionProxy
constructor
A new instance of CollectionProxy.
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
#records ⇒ Object (readonly)
Returns the value of attribute records.
8 9 10 |
# File 'lib/active_zuora/collection_proxy.rb', line 8 def records @records end |
#zobject_class ⇒ Object (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 |
#each ⇒ Object
29 30 31 |
# File 'lib/active_zuora/collection_proxy.rb', line 29 def each records.each { |r| yield r } end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/active_zuora/collection_proxy.rb', line 33 def empty? records.empty? end |