Module: Bali::Objector::Statics
- Defined in:
- lib/bali/objector.rb
Instance Method Summary collapse
- #can?(subtarget, operation, record = self) ⇒ Boolean
- #cant?(subtarget, operation, record = self) ⇒ Boolean
Instance Method Details
#can?(subtarget, operation, record = self) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bali/objector.rb', line 18 def can?(subtarget, operation, record = self) # if performed on a class-level, don't call its class or it will return # Class. That's not what is expected. if self.is_a?(Class) rule_group = Bali.rule_group_for(self, subtarget) else rule_group = Bali.rule_group_for(self.class, subtarget) end # default of can? is false whenever RuleClass for that class is undefined # or RuleGroup for that subtarget is not defined return false if rule_group.nil? # get the specific rule rule = rule_group.get_rule(:can, operation) # godly subtarget is allowed to do as he wishes # so long that the rule is not specificly defined return true if rule_group.zeus? && rule.nil? # plan subtarget is not allowed unless spesificly defined return false if rule_group.plant? && rule.nil? # default to false when asked about can? but no rule to be found return false if rule.nil? if rule.has_decider? # must test first decider = rule.decider if decider.arity == 0 decider.() == true else decider.(record) == true end else # rule is properly defined return true end end |
#cant?(subtarget, operation, record = self) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bali/objector.rb', line 58 def cant?(subtarget, operation, record = self) if self.is_a?(Class) rule_group = Bali.rule_group_for(self, subtarget) else rule_group = Bali.rule_group_for(self.class, subtarget) end # default of cant? is true whenever RuleClass for that class is undefined # or RuleGroup for that subtarget is not defined return true if rule_group.nil? rule = rule_group.get_rule(:cant, operation) # godly subtarget is not to be prohibited in his endeavours # so long that no specific rule about this operation is defined return false if rule_group.zeus? && rule.nil? # plant subtarget is not allowed to do things unless specificly defined return true if rule_group.plant? && rule.nil? # default to true when asked about cant? but no rule to be found return true if rule.nil? if rule.has_decider? decider = rule.decider if decider.arity == 0 decider.() == true else decider.(record) == true end end end |