class Pagy::Keyset::ActiveRecord

Keyset adapter for ActiveRecord

def apply_select

Append the missing keyset keys if the set is restricted by select
def apply_select
  @set.select(*@keyset.keys)
end

def extract_keyset

Extract the keyset from the set
def extract_keyset
  @set.order_values.each_with_object({}) do |node, keyset|
    keyset[node.value.name.to_sym] = node.direction
  end
end

def filter_newest = @set.where(filter_newest_query, **@latest)

Filter the newest records
def filter_newest = @set.where(filter_newest_query, **@latest)

def keyset_attributes_from(record) = record.slice(*@keyset.keys)

Get the keyset attributes from the record
def keyset_attributes_from(record) = record.slice(*@keyset.keys)

def select? = !@set.select_values.empty?

Set with selected columns?
def select? = !@set.select_values.empty?

def typecast_latest(latest)

Typecast the latest attributes
def typecast_latest(latest)
  @set.model.new(latest).slice(latest.keys)
      .to_hash.transform_keys(&:to_sym)
end