Class: Rabarber::Core::Rule
- Inherits:
-
Object
- Object
- Rabarber::Core::Rule
- Defined in:
- lib/rabarber/core/rule.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#dynamic_rule ⇒ Object
readonly
Returns the value of attribute dynamic_rule.
-
#negated_dynamic_rule ⇒ Object
readonly
Returns the value of attribute negated_dynamic_rule.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #dynamic_rule_followed?(dynamic_rule_receiver) ⇒ Boolean
-
#initialize(action, roles, dynamic_rule, negated_dynamic_rule) ⇒ Rule
constructor
A new instance of Rule.
- #roles_permitted?(roleable_roles) ⇒ Boolean
- #verify_access(roleable_roles, dynamic_rule_receiver) ⇒ Object
Constructor Details
#initialize(action, roles, dynamic_rule, negated_dynamic_rule) ⇒ Rule
Returns a new instance of Rule.
8 9 10 11 12 13 |
# File 'lib/rabarber/core/rule.rb', line 8 def initialize(action, roles, dynamic_rule, negated_dynamic_rule) @action = action @roles = Array(roles) @dynamic_rule = dynamic_rule @negated_dynamic_rule = negated_dynamic_rule end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/rabarber/core/rule.rb', line 6 def action @action end |
#dynamic_rule ⇒ Object (readonly)
Returns the value of attribute dynamic_rule.
6 7 8 |
# File 'lib/rabarber/core/rule.rb', line 6 def dynamic_rule @dynamic_rule end |
#negated_dynamic_rule ⇒ Object (readonly)
Returns the value of attribute negated_dynamic_rule.
6 7 8 |
# File 'lib/rabarber/core/rule.rb', line 6 def negated_dynamic_rule @negated_dynamic_rule end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
6 7 8 |
# File 'lib/rabarber/core/rule.rb', line 6 def roles @roles end |
Instance Method Details
#dynamic_rule_followed?(dynamic_rule_receiver) ⇒ Boolean
25 26 27 |
# File 'lib/rabarber/core/rule.rb', line 25 def dynamic_rule_followed?(dynamic_rule_receiver) !!(execute_dynamic_rule(dynamic_rule_receiver, false) && execute_dynamic_rule(dynamic_rule_receiver, true)) end |
#roles_permitted?(roleable_roles) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/rabarber/core/rule.rb', line 19 def roles_permitted?(roleable_roles) return false if Rabarber::Configuration.instance.must_have_roles && roleable_roles.empty? roles.empty? || roles.intersection(roleable_roles).any? end |
#verify_access(roleable_roles, dynamic_rule_receiver) ⇒ Object
15 16 17 |
# File 'lib/rabarber/core/rule.rb', line 15 def verify_access(roleable_roles, dynamic_rule_receiver) roles_permitted?(roleable_roles) && dynamic_rule_followed?(dynamic_rule_receiver) end |