Sha256: d3503df9ac52201081675ed02d6fea7cadbb6826c0f2756e2221462d0f23539b

Contents?: true

Size: 787 Bytes

Versions: 6

Compression:

Stored size: 787 Bytes

Contents

module Syncano
  module Resources
    class Collection
      include Enumerable

      delegate :last, :[], to: :collection

      def self.from_database(response, scope, element_class)
        new response, scope, element_class, true
      end

      def each(&block)
        collection.each &block
      end

      def prev?
        @prev
      end

      def next?
        @next
      end

      private

      attr_accessor :collection

      def initialize(response, scope, element_class, from_database)
        @prev, @next = response['prev'].present?, response['next'].present?
        self.collection = response['objects'].map do |attributes|
          element_class.new scope.connection, scope.scope_parameters, attributes, from_database
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
syncano-4.0.0.alpha4 lib/syncano/resources/collection.rb
syncano-4.0.0.alpha3 lib/syncano/resources/collection.rb
syncano-4.0.0.alpha2 lib/syncano/resources/collection.rb
syncano-4.0.0.alpha1 lib/syncano/resources/collection.rb
syncano-4.0.0.alpha lib/syncano/resources/collection.rb
syncano-4.0.0.pre lib/syncano/resources/collection.rb