Class: Aequitas::Rule::Guard
- Inherits:
-
Object
- Object
- Aequitas::Rule::Guard
- Extended by:
- ValueObject
- Defined in:
- lib/aequitas/rule/guard.rb
Instance Attribute Summary (collapse)
-
- (Object) if_test
readonly
Returns the value of attribute if_test.
-
- (Object) unless_test
readonly
Returns the value of attribute unless_test.
Attributes included from ValueObject
Instance Method Summary (collapse)
-
- (Boolean) allow?(resource)
private
Determines if this RuleGuard allows the given resource by evaluating the if_test and unless_test.
- - (Object) evaluate_conditional_clause(resource, clause) private
-
- (Guard) initialize(options = {})
constructor
A new instance of Guard.
Methods included from ValueObject
Constructor Details
- (Guard) initialize(options = {})
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
- (Object) if_test (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 |
- (Object) unless_test (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
- (Boolean) allow?(resource)
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 |
- (Object) evaluate_conditional_clause(resource, clause)
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 |