Class: Aequitas::Rule::Guard
- Inherits:
-
Object
- Object
- Aequitas::Rule::Guard
- Extended by:
- ValueObject
- Defined in:
- lib/aequitas/rule/guard.rb
Instance Attribute Summary collapse
-
#if_test ⇒ Object
readonly
Returns the value of attribute if_test.
-
#unless_test ⇒ Object
readonly
Returns the value of attribute unless_test.
Attributes included from ValueObject
Instance Method Summary collapse
-
#allow?(resource) ⇒ Boolean
private
Determines if this RuleGuard allows the given resource by evaluating the if_test and unless_test.
- #evaluate_conditional_clause(resource, clause) ⇒ Object private
-
#initialize(options = {}) ⇒ Guard
constructor
A new instance of Guard.
Methods included from ValueObject
Constructor Details
#initialize(options = {}) ⇒ Guard
Returns a new instance of Guard.
15 16 17 18 |
# File 'lib/aequitas/rule/guard.rb', line 15 def initialize( = {}) @if_test = .fetch(:if, nil) @unless_test = .fetch(:unless, nil) end |
Instance Attribute Details
#if_test ⇒ Object (readonly)
Returns the value of attribute if_test.
12 13 14 |
# File 'lib/aequitas/rule/guard.rb', line 12 def if_test @if_test end |
#unless_test ⇒ Object (readonly)
Returns the value of attribute unless_test.
13 14 15 |
# File 'lib/aequitas/rule/guard.rb', line 13 def unless_test @unless_test end |
Instance Method Details
#allow?(resource) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if this RuleGuard allows the given resource by evaluating the if_test and unless_test
30 31 32 33 34 35 36 37 38 |
# File 'lib/aequitas/rule/guard.rb', line 30 def allow?(resource) if if_test !!evaluate_conditional_clause(resource, if_test) elsif unless_test !evaluate_conditional_clause(resource, unless_test) else true end end |
#evaluate_conditional_clause(resource, clause) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 44 45 46 47 |
# File 'lib/aequitas/rule/guard.rb', line 41 def evaluate_conditional_clause(resource, clause) if clause.respond_to?(:call) clause.call(resource) elsif clause.kind_of?(Symbol) resource.__send__(clause) end end |