Class: Bali::Judger::Judge
- Inherits:
-
Object
- Object
- Bali::Judger::Judge
show all
- Defined in:
- lib/bali/foundations/judger/judge.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(unconstructable = true) ⇒ Judge
this class is abstract, shouldn’t be initialized
34
35
36
37
38
39
|
# File 'lib/bali/foundations/judger/judge.rb', line 34
def initialize(unconstructable = true)
if unconstructable
raise Bali::Error, "Bali::Judge::Judger is unconstructable, properly construct by using build to get a concrete class!"
end
self
end
|
Instance Attribute Details
#cross_checking ⇒ Object
determine if this judger should not call other judger
31
32
33
|
# File 'lib/bali/foundations/judger/judge.rb', line 31
def cross_checking
@cross_checking
end
|
#operation ⇒ Object
Returns the value of attribute operation.
26
27
28
|
# File 'lib/bali/foundations/judger/judge.rb', line 26
def operation
@operation
end
|
#original_subtarget ⇒ Object
Returns the value of attribute original_subtarget.
24
25
26
|
# File 'lib/bali/foundations/judger/judge.rb', line 24
def original_subtarget
@original_subtarget
end
|
#record ⇒ Object
record can be the class, or an instance of a class
28
29
30
|
# File 'lib/bali/foundations/judger/judge.rb', line 28
def record
@record
end
|
#subtarget ⇒ Object
Returns the value of attribute subtarget.
25
26
27
|
# File 'lib/bali/foundations/judger/judge.rb', line 25
def subtarget
@subtarget
end
|
Class Method Details
.build(auth_level, options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/bali/foundations/judger/judge.rb', line 41
def self.build(auth_level, options = {})
judge = nil
if auth_level == :can
judge = Bali::Judger::PositiveJudge.new
elsif auth_level == :cannot
judge = Bali::Judger::NegativeJudge.new
else
raise Bali::Error, "Unable to find judge for `#{auth_level}` case"
end
judge.original_subtarget = options[:original_subtarget]
judge.subtarget = options[:subtarget]
judge.operation = options[:operation]
judge.record = options[:record]
judge.cross_checking = false
judge
end
|
Instance Method Details
#clone(options = {}) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/bali/foundations/judger/judge.rb', line 60
def clone(options = {})
if options[:reverse]
new_judge = Bali::Judger::Judge.build(self.reverse_auth_level)
else
new_judge = Bali::Judger::Judge.build(self.auth_level)
end
new_judge.subtarget = subtarget
new_judge.operation = operation
new_judge.record = record
new_judge.cross_checking = cross_checking
new_judge.original_subtarget = original_subtarget
new_judge
end
|
#judgement(options = {}) ⇒ Object
return either true or false options can specify if returning raw, by specifying holy: true
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/bali/foundations/judger/judge.rb', line 127
def judgement(options = {})
our_holy_judgement = nil
if rule_group.nil?
if other_rule_group.nil?
our_holy_judgement = natural_value
end
end
if our_holy_judgement.nil? && need_to_check_for_intervention?
our_holy_judgement = check_intervention
end
if our_holy_judgement.nil? &&
rule_group && rule_group.plant? &&
rule.nil? && otherly_rule.nil?
our_holy_judgement = natural_value
end
if our_holy_judgement.nil? && rule.nil?
cross_check_value = nil
unless cross_checking
reversed_self = self.clone reverse: true
reversed_self.cross_checking = true
cross_check_value = reversed_self.judgement holy: true
end
if cross_check_value.nil?
if rule_group
if rule_group.plant?
our_holy_judgement = plant_return_value
end
if rule_group.zeus?
our_holy_judgement = zeus_return_value
end
end
else
if can_use_otherly_rule?(cross_check_value, cross_checking)
self.rule = otherly_rule
else
our_holy_judgement = cross_check_reverse_value(cross_check_value)
end
end
end
if our_holy_judgement.nil? && rule
if rule.has_decider?
our_holy_judgement = get_decider_result(rule, original_subtarget, record)
else
our_holy_judgement = default_positive_return_value
end
end
if our_holy_judgement.nil? && rule.nil? && (other_rule_group && other_rule_group.get_rule(reverse_auth_level, operation))
if rule_group && (rule_group.zeus? || rule_group.plant?)
else
our_holy_judgement = default_negative_fuzy_return_value
end
end
if our_holy_judgement.nil?
if otherly_rule
our_holy_judgement = BALI_FUZY_TRUE
else
our_holy_judgement = natural_value
end
end
holy = !!options[:holy]
return holy ? our_holy_judgement : translate_holy_judgement(our_holy_judgement)
end
|
#other_rule_group ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/bali/foundations/judger/judge.rb', line 88
def other_rule_group
unless @other_rule_group_checked
@other_rule_group = Bali::Integrator::RuleGroup.for(record_class, "__*__")
@other_rule_group_checked = true
end
@other_rule_group
end
|
#otherly_rule ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/bali/foundations/judger/judge.rb', line 114
def otherly_rule
unless @otherly_rule_checked
if other_rule_group
@otherly_rule = other_rule_group.get_rule(auth_level, operation)
@otherly_rule_checked = true
end
end
@otherly_rule
end
|
#record_class ⇒ Object
76
77
78
|
# File 'lib/bali/foundations/judger/judge.rb', line 76
def record_class
record.is_a?(Class) ? record : record.class
end
|
#rule ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/bali/foundations/judger/judge.rb', line 96
def rule
unless @rule_checked
if rule_group
@rule = rule_group.get_rule(auth_level, operation)
else
self.rule = nil
end
end
@rule
end
|
#rule=(the_rule) ⇒ Object
108
109
110
111
112
|
# File 'lib/bali/foundations/judger/judge.rb', line 108
def rule=(the_rule)
@rule = the_rule
@rule_checked = true
@rule
end
|
#rule_group ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/bali/foundations/judger/judge.rb', line 80
def rule_group
unless @rule_group_checked
@rule_group = Bali::Integrator::RuleGroup.for(record_class, subtarget)
@rule_group_checked = true
end
@rule_group
end
|