class ForemanApiClient::PagedResponse
like the WillPaginate collection
Attributes
page[RW]
results[RW]
total[RW]
Public Class Methods
new(json)
click to toggle source
per_page, search, sort
# File lib/foreman_api_client/paged_response.rb, line 12 def initialize(json) if json.kind_of?(Hash) && json["results"] @results = json["results"] @total = json["total"].to_i @page = json["page"] else @results = json.kind_of?(Array) ? json : Array[json] @total = json.size @page = 1 end end
Public Instance Methods
==(other)
click to toggle source
# File lib/foreman_api_client/paged_response.rb, line 32 def ==(other) results == other.results end
denormalize()
click to toggle source
# File lib/foreman_api_client/paged_response.rb, line 36 def denormalize self.class.new( results.collect do |record| ancestors(results, record["ancestry"]).each_with_object({}) do |ancestor, h| h.merge!(ancestor.select { |_n, v| !v.nil? && v != "" }) end.merge!(record.select { |_n, v| !v.nil? && v != "" }) end ) end
map!(&block)
click to toggle source
modify the structure inline
# File lib/foreman_api_client/paged_response.rb, line 27 def map!(&block) self.results = results.map(&block) self end
Private Instance Methods
ancestors(records, ancestry)
click to toggle source
# File lib/foreman_api_client/paged_response.rb, line 48 def ancestors(records, ancestry) (ancestry || "").split("/").collect(&:to_i).collect { |id| records.detect { |r| r["id"] == id } } end