Module: ActiveControl::Ability
- Defined in:
- lib/active_control/ability.rb
Overview
Active Control Ability
Creates two methods can?
and cannot?
to check if a remote object allows this object to perform a specific action on it.
To implement, just include ActiveControl::Ability
in your class:
class User
include ActiveControl::Ability
end
Those two methods requires that the remote object implements an authorize?
method that returns a boolean.
A minimal implementation could be:
class User
include ActiveControl::Ability
end
class Post
def (*args)
true
end
end
You could then do something like this:
user = User.new
post = Post.new
puts user.can?(:update, post)
>> true
Instead of defining an authorize?
method manually you could also implement ActiveControl::Authorization on the remote object.
Instance Method Summary collapse
Instance Method Details
#can?(action, remote_object) ⇒ Boolean
39 40 41 |
# File 'lib/active_control/ability.rb', line 39 def can?(action, remote_object) remote_object.(self, action) end |
#cannot?(*args) ⇒ Boolean
43 44 45 |
# File 'lib/active_control/ability.rb', line 43 def cannot?(*args) !can?(*args) end |