Sha256: b14963b2897d8865de493e90c00691e34ec90b00be001a50d6b19e279305c6de

Contents?: true

Size: 770 Bytes

Versions: 10

Compression:

Stored size: 770 Bytes

Contents

module HaveAPI::Client
  # A list of ResourceInstance objects.
  class ResourceInstanceList < Array
    def initialize(client, api, resource, action, response)
      super()
      @response = response

      response.response.each do |hash|
        self << ResourceInstance.new(client, api, resource, action:, response: hash)
      end
    end

    # Return the API response that created this object.
    def api_response
      @response
    end

    def meta
      @response.meta
    end

    # Return the total count of items.
    # Note that for this method to work, the action that returns this
    # object list must be invoked with +meta: {count: true}+, otherwise
    # the object count is not sent.
    def total_count
      meta[:total_count]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
haveapi-client-0.23.5 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.23.4 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.23.3 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.23.2 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.23.1 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.23.0 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.22.1 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.22.0 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.21.1 lib/haveapi/client/resource_instance_list.rb
haveapi-client-0.21.0 lib/haveapi/client/resource_instance_list.rb