Class: Veto::ConditionsEvaluator
- Inherits:
-
Object
- Object
- Veto::ConditionsEvaluator
- Defined in:
- lib/veto/conditions_evaluator.rb
Class Method Summary collapse
- .truthy?(condition, context, entity) ⇒ Boolean
- .truthy_conditions?(conditions, context, entity) ⇒ Boolean
Class Method Details
.truthy?(condition, context, entity) ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/veto/conditions_evaluator.rb', line 3 def self.truthy? condition, context, entity case condition when String !!entity.instance_eval(condition) when Symbol !!context.send(condition) when Proc !!condition.call(entity) else !!condition end end |
.truthy_conditions?(conditions, context, entity) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/veto/conditions_evaluator.rb', line 16 def self.truthy_conditions? conditions, context, entity return true if !conditions.key?(:if) && !conditions.key?(:unless) [*conditions[:if]].each do |condition| return false unless truthy?(condition, context, entity) end [*conditions[:unless]].each do |condition| return false if truthy?(condition, context, entity) end true end |