Class: PandaCms::AdminConstraint
- Inherits:
-
Object
- Object
- PandaCms::AdminConstraint
- Defined in:
- app/constraints/panda_cms/admin_constraint.rb
Instance Method Summary collapse
- #current_user(request) ⇒ Object
-
#initialize(&block) ⇒ AdminConstraint
constructor
A new instance of AdminConstraint.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ AdminConstraint
Returns a new instance of AdminConstraint.
3 4 5 |
# File 'app/constraints/panda_cms/admin_constraint.rb', line 3 def initialize(&block) @block = block end |
Instance Method Details
#current_user(request) ⇒ Object
12 13 14 |
# File 'app/constraints/panda_cms/admin_constraint.rb', line 12 def current_user(request) User.find_by(id: request.session[:user_id]) end |
#matches?(request) ⇒ Boolean
7 8 9 10 |
# File 'app/constraints/panda_cms/admin_constraint.rb', line 7 def matches?(request) user = current_user(request) user.present? && user.admin? && @block&.call(user) end |