Sha256: 43044a5d3da014f1f1dfb8fb838f63f21bd4c60219f79a9448204433499bab0c

Contents?: true

Size: 757 Bytes

Versions: 3

Compression:

Stored size: 757 Bytes

Contents

module RemoteResource
  class Collection
    include Enumerable

    delegate :[], :at, :reverse, :size, to: :to_a

    attr_reader :resource_klass, :resources_collection, :_response

    def initialize(resource_klass, resources_collection, response_hash)
      @resource_klass       = resource_klass
      @resources_collection = resources_collection
      @response_hash        = response_hash
      @_response            = response_hash[:_response]
    end

    def each
      if resources_collection.is_a? Array
        resources_collection.each { |element| yield resource_klass.new element.merge(@response_hash) }
      end
    end

    def empty?
      resources_collection.blank?
    end

    def success?
      _response.success?
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ddy_remote_resource-0.4.4 lib/remote_resource/collection.rb
ddy_remote_resource-0.4.3 lib/remote_resource/collection.rb
ddy_remote_resource-0.4.2 lib/remote_resource/collection.rb