Module: Card::Rule::All

Included in:
Card
Defined in:
lib/card/rule/all.rb

Overview

rule-related Card instance methods

Instance Method Summary collapse

Instance Method Details

#preference(setting_code, user = nil) ⇒ Object



17
18
19
# File 'lib/card/rule/all.rb', line 17

def preference setting_code, user=nil
  preference_card(setting_code, user, skip_modules: true)&.db_content
end

#preference?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/card/rule/all.rb', line 42

def preference?
  name.parts.length > 2 &&
    (Card.fetch_type_id(name.right) == SettingID) &&
    (Card.fetch_type_id(name[0..-3]) == SetID) &&
    valid_preferer?
end

#preference_card(setting_code, user = nil, options = {}) ⇒ Object



21
22
23
# File 'lib/card/rule/all.rb', line 21

def preference_card setting_code, user=nil, options={}
  Card.fetch preference_card_id(setting_code, user), options
end

#preference_card_id(setting_code, user = nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/card/rule/all.rb', line 25

def preference_card_id setting_code, user=nil
  return unless (user_id = preference_user_id user)

  rule_id_lookup Card::Rule.preference_cache,
                 "#{setting_code}+#{user_id}",
                 "#{setting_code}+#{AllID}"
end

#rule(setting_code) ⇒ Object



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

def rule setting_code
  rule_card(setting_code, skip_modules: true)&.db_content
end

#rule?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/card/rule/all.rb', line 33

def rule?
  standard_rule? || preference?
end

#rule_card(setting_code, options = {}) ⇒ Object



9
10
11
# File 'lib/card/rule/all.rb', line 9

def rule_card setting_code, options={}
  Card.fetch rule_card_id(setting_code), options
end

#rule_card_id(setting_code) ⇒ Object



13
14
15
# File 'lib/card/rule/all.rb', line 13

def rule_card_id setting_code
  rule_id_lookup Card::Rule.rule_cache, setting_code
end

#standard_rule?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/card/rule/all.rb', line 37

def standard_rule?
  (Card.fetch_type_id(name.right) == SettingID) &&
    (Card.fetch_type_id(name.left) == SetID)
end