Class: Search

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/search.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete_old_searches(days_old) ⇒ Object

delete old, unsaved searches

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'app/models/search.rb', line 19

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

Instance Method Details

#saved?Boolean

A Search instance is considered a saved search if it has a user_id.

Returns:

  • (Boolean)


14
15
16
# File 'app/models/search.rb', line 14

def saved?
  user_id?
end