class Insights::API::Common::GraphQL::AssociatedRecords

Public Class Methods

new(collection) click to toggle source
# File lib/insights/api/common/graphql/associated_records.rb, line 11
def initialize(collection)
  @collection = collection
end

Private Instance Methods

filter_collection_by_options(options) click to toggle source
# File lib/insights/api/common/graphql/associated_records.rb, line 27
def filter_collection_by_options(options)
  res = @collection
  if options[:where].present?
    options[:where].each_pair { |k, v| res = res.select { |rec| rec[k].to_s == v.to_s } }
  end
  if options[:order].present?
    order_by = options[:order].first
    res = res.sort_by { |rec| rec[order_by] }
  end
  res = res.drop(options[:offset]) if options[:offset]
  res = res.take(options[:limit])  if options[:limit]
  res
end