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.
38 39 40 41 |
# File 'app/policies/policy.rb', line 38 def initialize(user, record = nil) @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
36 37 38 |
# File 'app/policies/policy.rb', line 36 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
36 37 38 |
# File 'app/policies/policy.rb', line 36 def user @user end |
Class Method Details
.collection(user) ⇒ Object
52 53 54 |
# File 'app/policies/policy.rb', line 52 def collection(user) new(user) end |
.for(user, object) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/policies/policy.rb', line 44 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
56 57 58 |
# File 'app/policies/policy.rb', line 56 def member(user, record) new(user, record) end |