Class: SkinnyControllers::Policy::Base
- Inherits:
-
Object
- Object
- SkinnyControllers::Policy::Base
- Defined in:
- lib/skinny_controllers/policy/base.rb
Instance Attribute Summary collapse
-
#authorized_via_parent ⇒ Object
Returns the value of attribute authorized_via_parent.
-
#object ⇒ Object
Returns the value of attribute object.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#default? ⇒ Boolean
if a method is not defined for a particular verb or action, this will be used.
-
#initialize(user, object, authorized_via_parent: false) ⇒ Base
constructor
A new instance of Base.
-
#read?(o = object) ⇒ Boolean
this should be used when checking access to a single object.
-
#read_all? ⇒ Boolean
this should be used when checking access to multilpe objects it will call
read?on each object of the array.
Constructor Details
#initialize(user, object, authorized_via_parent: false) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 |
# File 'lib/skinny_controllers/policy/base.rb', line 11 def initialize(user, object, authorized_via_parent: false) self.user = user self.object = object self. = end |
Instance Attribute Details
#authorized_via_parent ⇒ Object
Returns the value of attribute authorized_via_parent.
4 5 6 |
# File 'lib/skinny_controllers/policy/base.rb', line 4 def end |
#object ⇒ Object
Returns the value of attribute object.
4 5 6 |
# File 'lib/skinny_controllers/policy/base.rb', line 4 def object @object end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/skinny_controllers/policy/base.rb', line 4 def user @user end |
Instance Method Details
#default? ⇒ Boolean
if a method is not defined for a particular verb or action, this will be used.
23 24 25 |
# File 'lib/skinny_controllers/policy/base.rb', line 23 def default? SkinnyControllers.allow_by_default end |
#read?(o = object) ⇒ Boolean
this should be used when checking access to a single object
28 29 30 |
# File 'lib/skinny_controllers/policy/base.rb', line 28 def read?(o = object) o.send(accessible_method, user) end |
#read_all? ⇒ Boolean
this should be used when checking access to multilpe objects it will call read? on each object of the array
if the operation used a scope to find records from an association, then authorized_via_parent could be true, in which case, the loop would be skipped.
TODO: think of a way to override the authorized_via_parent functionality
40 41 42 43 44 45 46 47 48 |
# File 'lib/skinny_controllers/policy/base.rb', line 40 def read_all? return true if # This is expensive, so try to avoid it # TODO: look in to creating a cache for # these look ups that's invalidated upon # object save accessible = object.map { |ea| read?(ea) } accessible.all? end |