Sha256: f4eb3f56a4efa36e15b812a4b4439b0c4d9ccec4e4310be559f55a7f1e83a3f6

Contents?: true

Size: 586 Bytes

Versions: 54

Compression:

Stored size: 586 Bytes

Contents

# frozen_string_literal: true

class Search < ApplicationRecord
  belongs_to :user, optional: true

  serialize :query_params

  # 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

54 entries across 54 versions & 1 rubygems

Version Path
blacklight-7.27.1 app/models/search.rb
blacklight-7.27.0 app/models/search.rb
blacklight-7.26.1 app/models/search.rb
blacklight-7.26.0 app/models/search.rb
blacklight-7.25.3 app/models/search.rb
blacklight-7.25.2 app/models/search.rb
blacklight-7.25.1 app/models/search.rb
blacklight-7.25.0 app/models/search.rb
blacklight-7.24.0 app/models/search.rb
blacklight-7.23.0.1 app/models/search.rb
blacklight-7.23.0 app/models/search.rb
blacklight-7.22.2 app/models/search.rb
blacklight-7.22.1 app/models/search.rb
blacklight-7.22.0 app/models/search.rb
blacklight-7.21.2 app/models/search.rb
blacklight-7.21.1 app/models/search.rb
blacklight-7.21.0 app/models/search.rb
blacklight-7.20.1 app/models/search.rb
blacklight-7.20.0 app/models/search.rb
blacklight-7.19.2 app/models/search.rb