Class: Policy
Direct Known Subclasses
InvitePolicy, PageFilePolicy, PageImagePolicy, PagePolicy, UserPolicy
Defined Under Namespace
Modules: DefaultPolicy
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, record = nil) ⇒ Policy
constructor
A new instance of Policy.
Methods included from DefaultPolicy
#create?, #destroy?, #edit?, #index, #new?, #show?, #update?
Constructor Details
#initialize(user, record = nil) ⇒ Policy
Returns a new instance of Policy.
36 37 38 39 |
# File 'app/policies/policy.rb', line 36 def initialize(user, record = nil) @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
34 35 36 |
# File 'app/policies/policy.rb', line 34 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
34 35 36 |
# File 'app/policies/policy.rb', line 34 def user @user end |
Class Method Details
.collection(user) ⇒ Object
50 51 52 |
# File 'app/policies/policy.rb', line 50 def collection(user) new(user) end |
.for(user, object) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/policies/policy.rb', line 42 def for(user, object) if object.is_a?(Class) "#{object}Policy".constantize.collection(user) else "#{object.class}Policy".constantize.member(user, object) end end |
.member(user, record) ⇒ Object
54 55 56 |
# File 'app/policies/policy.rb', line 54 def member(user, record) new(user, record) end |