Module: Card::Set::All::Rules
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod001-01_core/all/rules.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary
collapse
- RuleSQL =
~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/rules.rb ~~~~~~~~~~~
%{
select rules.id as rule_id, settings.id as setting_id, sets.id as set_id,
sets.left_id as anchor_id, sets.right_id as set_tag_id
from cards rules
join cards sets on rules.left_id = sets.id
join cards settings on rules.right_id = settings.id
where sets.type_id = #{Card::SetID } and sets.trash is false
and settings.type_id = #{Card::SettingID} and settings.trash is false
and rules.trash is false
and (settings.codename != 'follow' or rules.db_content != '');
}
- ReadRuleSQL =
%{
select refs.referee_id as party_id, read_rules.id as read_rule_id
from cards read_rules
join card_references refs on refs.referer_id = read_rules.id
join cards sets on read_rules.left_id = sets.id
where read_rules.right_id = #{Card::ReadID} and read_rules.trash is false and sets.type_id = #{Card::SetID};
}
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_on_format, ensure_set, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file
Methods included from Event
#define_event, #event
Instance Method Details
#is_rule? ⇒ Boolean
24
25
26
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 24
def is_rule?
is_standard_rule? || is_user_rule?
end
|
#is_standard_rule? ⇒ Boolean
28
29
30
31
32
33
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 28
def is_standard_rule?
(r = right( skip_modules: true )) &&
r.type_id == Card::SettingID &&
(l = left( skip_modules: true )) &&
l.type_id == Card::SetID
end
|
#is_user_rule? ⇒ Boolean
35
36
37
38
39
40
41
42
43
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 35
def is_user_rule?
cardname.parts.length > 2 &&
(r = right( skip_modules: true )) &&
r.type_id == Card::SettingID &&
(set = self[0..-3, skip_modules: true]) &&
set.type_id == Card::SetID &&
(user = self[-2, skip_modules: true] ) &&
(user.type_id == Card::UserID || user.codename == 'all' )
end
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 75
def related_sets with_self = false
sets = []
if known? && type_id == Card::CardtypeID sets << ["#{name}+*type", Card::TypeSet.label(name)]
end
if with_self
sets << ["#{name}+*self", Card::SelfSet.label(name)]
end
if known? && cardname.simple?
sets << ["#{name}+*right", Card::RightSet.label(name)]
end
sets
end
|
#rule(setting_code, options = {}) ⇒ Object
46
47
48
49
50
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 46
def rule setting_code, options={}
options[:skip_modules] = true
card = rule_card setting_code, options
card && card.db_content
end
|
#rule_card(setting_code, options = {}) ⇒ Object
52
53
54
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 52
def rule_card setting_code, options={}
Card.fetch rule_card_id(setting_code, options), options
end
|
#rule_card_id(setting_code, options = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'tmpsets/set/mod001-01_core/all/rules.rb', line 56
def rule_card_id setting_code, options={}
fallback = options.delete( :fallback )
if Card::Setting.user_specific? setting_code
user_id = options[:user_id] || (options[:user] and options[:user].id) || Auth.current_id
if user_id
fallback = "#{setting_code}+#{AllID}"
setting_code = "#{setting_code}+#{user_id}"
end
end
rule_set_keys.each do |rule_set_key|
rule_id = self.class.rule_cache["#{rule_set_key}+#{setting_code}"]
rule_id ||= fallback && self.class.rule_cache["#{rule_set_key}+#{fallback}"]
return rule_id if rule_id
end
nil
end
|