Sha256: b149c2f651f0b13a653353b2ba093140a457e8344cac1601f0b20d126aab8954

Contents?: true

Size: 794 Bytes

Versions: 11

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

class Search < ApplicationRecord
  belongs_to :user, optional: true

  if ::Rails.version.to_f >= 7.1
    # non-deprecated coder: keyword arg for Rails 7.1+
    serialize :query_params, coder: Blacklight::SearchParamsYamlCoder
  else
    serialize :query_params, Blacklight::SearchParamsYamlCoder
  end

  # A Search instance is considered a saved search if it has a user_id.
  def saved?
    user_id?
  end

  # delete old, unsaved searches
  def self.delete_old_searches(days_old)
    raise ArgumentError, 'days_old is expected to be a number' unless days_old.is_a?(Numeric)
    raise ArgumentError, 'days_old is expected to be greater than 0' if days_old <= 0

    where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).delete_all
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/models/search.rb
blacklight-8.6.0 app/models/search.rb
blacklight-8.5.1 app/models/search.rb
blacklight-8.5.0 app/models/search.rb
blacklight-8.4.0 app/models/search.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/models/search.rb
blacklight-8.3.0 app/models/search.rb
blacklight-8.2.2 app/models/search.rb
blacklight-8.2.1 app/models/search.rb
blacklight-8.2.0 app/models/search.rb
blacklight-8.1.0 app/models/search.rb