Sha256: fec46cf417592538912519334c8bb9f0eb7cb54f5635eb326018a3ec723c7b68

Contents?: true

Size: 442 Bytes

Versions: 2

Compression:

Stored size: 442 Bytes

Contents

module JsonApiClient
  class ResultSet < Array

    attr_accessor :total_pages, :total_entries, :offset, :per_page, :current_page, :errors

    def self.build(klass, data)
      result_data = data.fetch(klass.table_name, [])
      new(result_data.map {|attributes| klass.new(attributes) }).tap do |result_set|
        yield(result_set) if block_given?
      end
    end

    def has_errors?
      errors && errors.length > 0
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_api_client-0.2.0 lib/json_api_client/result_set.rb
json_api_client-0.1.3 lib/json_api_client/result_set.rb