Module: Card::Rule

Defined in:
lib/card/rule.rb,
lib/card/rule/all.rb,
lib/card/rule/cache.rb,
lib/card/rule/read_rule_cache.rb,
lib/card/rule/preference_cache.rb

Overview

Optimized handling of card “rules” (Set+Setting) and preferences.

Defined Under Namespace

Modules: All Classes: Cache, PreferenceCache, ReadRuleCache

Class Method Summary collapse

Class Method Details

.all_user_ids_with_rule_for(set_card, setting_code) ⇒ Object



47
48
49
50
51
# File 'lib/card/rule.rb', line 47

def all_user_ids_with_rule_for set_card, setting_code
  cache_key = "#{set_card.rule_cache_key_base}+#{setting_code}"
  user_ids = PreferenceCache.user_ids[cache_key] || []
  user_ids.include?(AllID) ? all_user_ids : user_ids
end

.clear_preference_cacheObject



31
32
33
# File 'lib/card/rule.rb', line 31

def clear_preference_cache
  PreferenceCache.clear
end

.clear_read_rule_cacheObject



35
36
37
# File 'lib/card/rule.rb', line 35

def clear_read_rule_cache
  ReadRuleCache.clear
end

.clear_rule_cacheObject



27
28
29
# File 'lib/card/rule.rb', line 27

def clear_rule_cache
  Cache.clear
end

.global_setting(name) ⇒ Object



5
6
7
8
9
# File 'lib/card/rule.rb', line 5

def global_setting name
  Auth.as_bot do
    (card = Card[name]) && !card.db_content.strip.empty? && card.db_content
  end
end

.preference_cacheObject



19
20
21
# File 'lib/card/rule.rb', line 19

def preference_cache
  PreferenceCache.read
end

.preference_names(user_name, setting_code) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/card/rule.rb', line 39

def preference_names user_name, setting_code
  Card.search({ right: { codename: setting_code },
                left: { left: { type_id: SetID },
                        right: user_name },
                return: :name },
              "preference cards for user: #{user_name}")
end

.read_rule_cacheObject



23
24
25
# File 'lib/card/rule.rb', line 23

def read_rule_cache
  ReadRuleCache.read
end

.rule_cacheObject



15
16
17
# File 'lib/card/rule.rb', line 15

def rule_cache
  Cache.read
end

.toggle(val) ⇒ Object



11
12
13
# File 'lib/card/rule.rb', line 11

def toggle val
  val.to_s.strip == "1"
end