class Card::Rule::PreferenceCache

Constants

USER_ID_CACHE_KEY

Public Class Methods

clear() click to toggle source
Calls superclass method Card::Rule::Cache::clear
# File lib/card/rule/preference_cache.rb, line 55
def clear
  super
  Card.cache.write USER_ID_CACHE_KEY, nil
end
lookup_key(row) click to toggle source
# File lib/card/rule/preference_cache.rb, line 66
def lookup_key row
  return unless (base = lookup_key_without_user row)

  "#{base}+#{row['user_id']}"
end
Also aliased as: lookup_key_without_user
lookup_key_without_user(row)
Alias for: lookup_key
populate() click to toggle source
Calls superclass method Card::Rule::Cache::populate
# File lib/card/rule/preference_cache.rb, line 35
def populate
  @rows = nil
  super.tap do
    populate_user_ids
    @rows = nil
  end
end
populate_user_ids() click to toggle source
# File lib/card/rule/preference_cache.rb, line 43
def populate_user_ids
  Card.cache.write USER_ID_CACHE_KEY, user_id_hash
end
rows() click to toggle source
Calls superclass method Card::Rule::Cache::rows
# File lib/card/rule/preference_cache.rb, line 60
def rows
  @rows ||= super
end
user_id_hash() click to toggle source
# File lib/card/rule/preference_cache.rb, line 47
def user_id_hash
  rows.each_with_object({}) do |row, hash|
    key = lookup_key_without_user row
    hash[key] ||= []
    hash[key] << row["user_id"]
  end
end
user_ids() click to toggle source
# File lib/card/rule/preference_cache.rb, line 31
def user_ids
  Card.cache.read(USER_ID_CACHE_KEY) || (populate && user_ids)
end