Sha256: 8534db67df9a75b3e4a4a1e5e5c01b320abb0ad5e8d486fe901682e7994091e4

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

module ActiveZuora
  class CollectionProxy
    
    include ZObject
    include Enumerable
    include BatchSubscribe
    
    attr_reader :records, :zobject_class

    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
    
    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

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
active_zuora-2.6.0 lib/active_zuora/collection_proxy.rb
active_zuora-2.5.4 lib/active_zuora/collection_proxy.rb
active_zuora-2.5.3 lib/active_zuora/collection_proxy.rb
active_zuora-2.5.2 lib/active_zuora/collection_proxy.rb
active_zuora-2.5.1 lib/active_zuora/collection_proxy.rb
active_zuora-2.5.0 lib/active_zuora/collection_proxy.rb
active_zuora-2.4.1 lib/active_zuora/collection_proxy.rb
active_zuora-2.4.0 lib/active_zuora/collection_proxy.rb
active_zuora-2.3.1 lib/active_zuora/collection_proxy.rb
active_zuora-2.3.0 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.7 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.6 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.5 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.4 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.3 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.2 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.1 lib/active_zuora/collection_proxy.rb
active_zuora-2.2.0 lib/active_zuora/collection_proxy.rb