Class: Faalis::ApplicationPolicy
- Inherits:
-
Object
- Object
- Faalis::ApplicationPolicy
- Defined in:
- app/policies/faalis/application_policy.rb
Overview
Main class for all the Faalis Policy classes. It’s totally a minimume Policy.
Direct Known Subclasses
ApplicationPolicy, GroupPolicy, UserMessagePolicy, UserPolicy
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #authorize?(action) ⇒ Boolean
-
#initialize(user, record) ⇒ ApplicationPolicy
constructor
A new instance of ApplicationPolicy.
- #method_missing(m, *args, &block_given) ⇒ Object
- #scope ⇒ Object
Constructor Details
#initialize(user, record) ⇒ ApplicationPolicy
Returns a new instance of ApplicationPolicy.
6 7 8 9 |
# File 'app/policies/faalis/application_policy.rb', line 6 def initialize(user, record) @user = user @record = record end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block_given) ⇒ Object
28 29 30 31 |
# File 'app/policies/faalis/application_policy.rb', line 28 def method_missing(m, *args, &block_given) return m.to_s[0..-2] if m.to_s =~ /.*\?$/ super end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
4 5 6 |
# File 'app/policies/faalis/application_policy.rb', line 4 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'app/policies/faalis/application_policy.rb', line 4 def user @user end |
Instance Method Details
#authorize?(action) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/policies/faalis/application_policy.rb', line 11 def (action) return false if @user.nil? return true if @user.admin? # Check for ownership of the reocrd record_class = @record.class unless [Class, String, Symbol].include?(record_class) if @user.has_ownership?(@record) return false if !@user.owned? @record end @record = @record.class end user.can? action, @record.to_s end |
#scope ⇒ Object
34 35 36 |
# File 'app/policies/faalis/application_policy.rb', line 34 def scope Pundit.policy_scope!(@user, record.class) end |