Class: DeclarativePolicy::Condition
- Inherits:
-
Object
- Object
- DeclarativePolicy::Condition
- Defined in:
- lib/declarative_policy/condition.rb
Overview
A Condition is the data structure that is created by the ‘condition` declaration on DeclarativePolicy::Base. It is more or less just a struct of the data passed to that declaration. It holds on to the block to be instance_eval’d on a context (instance of Base) later, via #compute.
Instance Attribute Summary collapse
-
#context_key ⇒ Object
readonly
Returns the value of attribute context_key.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#manual_score ⇒ Object
readonly
Returns the value of attribute manual_score.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #compute(context) ⇒ Object
-
#initialize(name, opts = {}, &compute) ⇒ Condition
constructor
A new instance of Condition.
- #key ⇒ Object
Constructor Details
#initialize(name, opts = {}, &compute) ⇒ Condition
Returns a new instance of Condition.
12 13 14 15 16 17 18 19 |
# File 'lib/declarative_policy/condition.rb', line 12 def initialize(name, opts = {}, &compute) @name = name @compute = compute @scope = opts.fetch(:scope, :normal) @description = opts.delete(:description) @context_key = opts[:context_key] @manual_score = opts.fetch(:score, nil) end |
Instance Attribute Details
#context_key ⇒ Object (readonly)
Returns the value of attribute context_key.
10 11 12 |
# File 'lib/declarative_policy/condition.rb', line 10 def context_key @context_key end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
10 11 12 |
# File 'lib/declarative_policy/condition.rb', line 10 def description @description end |
#manual_score ⇒ Object (readonly)
Returns the value of attribute manual_score.
10 11 12 |
# File 'lib/declarative_policy/condition.rb', line 10 def manual_score @manual_score end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/declarative_policy/condition.rb', line 10 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
10 11 12 |
# File 'lib/declarative_policy/condition.rb', line 10 def scope @scope end |
Instance Method Details
#compute(context) ⇒ Object
21 22 23 |
# File 'lib/declarative_policy/condition.rb', line 21 def compute(context) !!context.instance_eval(&@compute) end |
#key ⇒ Object
25 26 27 |
# File 'lib/declarative_policy/condition.rb', line 25 def key "#{@context_key}/#{@name}" end |