Class: ActionGuard::LevelRule
- Inherits:
-
Object
- Object
- ActionGuard::LevelRule
- Defined in:
- lib/action-guard/rules.rb
Instance Method Summary collapse
- #allows?(person, request_params) ⇒ Boolean
-
#initialize(allowed_level, to_allowed_level, role_leveler, &proc) ⇒ LevelRule
constructor
A new instance of LevelRule.
Constructor Details
#initialize(allowed_level, to_allowed_level, role_leveler, &proc) ⇒ LevelRule
Returns a new instance of LevelRule.
13 14 15 16 17 18 |
# File 'lib/action-guard/rules.rb', line 13 def initialize(allowed_level, to_allowed_level, role_leveler, &proc) @role_leveler = role_leveler @allowed_level = allowed_level @to_allowed_level = to_allowed_level @additional_rule = proc end |
Instance Method Details
#allows?(person, request_params) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/action-guard/rules.rb', line 20 def allows?(person, request_params) return false unless person return false unless @role_leveler.role(person.role) >= @role_leveler.role(@allowed_level) return false if @to_allowed_level && @role_leveler.role(@to_allowed_level) < @role_leveler.role(person.role) return true unless @additional_rule return @additional_rule.call(person, request_params) end |