module NdrError::Finder

Module to help with searching through fingerprints / logs.

Public Instance Methods

find(id) click to toggle source

Sends finds through to the fingerprint resource.

# File lib/ndr_error/finder.rb, line 27
def find(id)
  Fingerprint.find(id)
end
paginate(keywords, page) click to toggle source

Proxy to paginate fingerprint results, filtering them if search keywords have been supplied.

# File lib/ndr_error/finder.rb, line 22
def paginate(keywords, page)
  search(keywords).paginate(page: page, per_page: Fingerprint.per_page)
end

Private Instance Methods

order(records) click to toggle source

Intelligent search order:

Bring records that have matched multiple times
to the front, but attempt to maintain the
created_at DESC order within groups.
# File lib/ndr_error/finder.rb, line 39
def order(records)
  grouped = records.group_by { |record| records.count(record) }.each do |_count, group|
    group.sort! do |a, b|
      [b.updated_at, b.error_fingerprintid] <=> [a.updated_at, a.error_fingerprintid]
    end
  end

  grouped.values.flatten.uniq
end