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.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#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_rules_followed?(controller_instance) ⇒ Boolean
-
#initialize(action, roles, context, dynamic_rule, negated_dynamic_rule) ⇒ Rule
constructor
A new instance of Rule.
- #roles_permitted?(roleable, controller_instance) ⇒ Boolean
- #verify_access(roleable, controller_instance) ⇒ Object
Constructor Details
#initialize(action, roles, context, dynamic_rule, negated_dynamic_rule) ⇒ Rule
Returns a new instance of Rule.
8 9 10 11 12 13 14 |
# File 'lib/rabarber/core/rule.rb', line 8 def initialize(action, roles, context, dynamic_rule, negated_dynamic_rule) @action = action @roles = Array(roles) @context = context @dynamic_rule = dynamic_rule || -> { true } @negated_dynamic_rule = negated_dynamic_rule || -> { false } 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 |
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/rabarber/core/rule.rb', line 6 def context @context 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_rules_followed?(controller_instance) ⇒ Boolean
27 28 29 |
# File 'lib/rabarber/core/rule.rb', line 27 def dynamic_rules_followed?(controller_instance) execute_rule(controller_instance, dynamic_rule) && !execute_rule(controller_instance, negated_dynamic_rule) end |
#roles_permitted?(roleable, controller_instance) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/rabarber/core/rule.rb', line 20 def roles_permitted?(roleable, controller_instance) resolved_context = resolve_context(controller_instance) return false if Rabarber::Configuration.instance.must_have_roles && roleable.roles(context: resolved_context).empty? roles.empty? || roleable.has_role?(*roles, context: resolved_context) end |
#verify_access(roleable, controller_instance) ⇒ Object
16 17 18 |
# File 'lib/rabarber/core/rule.rb', line 16 def verify_access(roleable, controller_instance) roles_permitted?(roleable, controller_instance) && dynamic_rules_followed?(controller_instance) end |