Class: Card::Rule::Cache
- Inherits:
-
Object
show all
- Defined in:
- lib/card/rule/cache.rb
Class Method Summary
collapse
Class Method Details
.clear ⇒ Object
35
36
37
|
# File 'lib/card/rule/cache.rb', line 35
def clear
Card.cache.write cache_key, nil
end
|
.lookup_hash ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/card/rule/cache.rb', line 39
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) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/card/rule/cache.rb', line 47
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) ⇒ Object
56
57
58
59
|
# File 'lib/card/rule/cache.rb', line 56
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
|
.populate ⇒ Object
31
32
33
|
# File 'lib/card/rule/cache.rb', line 31
def populate
Card.cache.write cache_key, lookup_hash
end
|
.read ⇒ Object
27
28
29
|
# File 'lib/card/rule/cache.rb', line 27
def read
Card.cache.read(cache_key) || populate
end
|
.rows ⇒ Object
65
66
67
|
# File 'lib/card/rule/cache.rb', line 65
def rows
Card.connection.select_all sql
end
|
.setting_code(row) ⇒ Object
61
62
63
|
# File 'lib/card/rule/cache.rb', line 61
def setting_code row
Card::Codename[row["setting_id"].to_i]
end
|