class Card::Rule::Cache
Public Class Methods
clear()
click to toggle source
# File lib/card/rule/cache.rb, line 35 def clear Card.cache.write cache_key, nil end
populate()
click to toggle source
# File lib/card/rule/cache.rb, line 31 def populate Card.cache.write cache_key, lookup_hash end
read()
click to toggle source
# File lib/card/rule/cache.rb, line 27 def read Card.cache.read(cache_key) || populate end
Private Class Methods
lookup_hash()
click to toggle source
# File lib/card/rule/cache.rb, line 41 def lookup_hash rows.each_with_object({}) do |row, hash| next unless (key = lookup_key row) hash[key] = row["rule_id"].to_i end end
lookup_key(row)
click to toggle source
# File lib/card/rule/cache.rb, line 49 def lookup_key row return false unless (setting_code = setting_code(row)) anchor_id = row["anchor_id"] return false unless (pattern_code = pattern_code(anchor_id, row)) [anchor_id, pattern_code, setting_code].compact.map(&:to_s).join "+" end
pattern_code(anchor_id, row)
click to toggle source
# File lib/card/rule/cache.rb, line 58 def pattern_code anchor_id, row set_class_id = anchor_id.nil? ? row["set_id"] : row["set_tag_id"] Card::Codename[set_class_id.to_i] end
rows()
click to toggle source
# File lib/card/rule/cache.rb, line 67 def rows Card.connection.select_all sql end
setting_code(row)
click to toggle source
# File lib/card/rule/cache.rb, line 63 def setting_code row Card::Codename[row["setting_id"].to_i] end