Class: Accessly::PermittedActions::Query
- Defined in:
- lib/accessly/permitted_actions/query.rb
Instance Method Summary collapse
-
#can?(action_id, object_type) ⇒ Boolean
Ask whether the actor has permission to perform action_id in the given namespace.
-
#initialize(actors, segment_id) ⇒ Query
constructor
A new instance of Query.
Constructor Details
#initialize(actors, segment_id) ⇒ Query
Returns a new instance of Query.
7 8 9 |
# File 'lib/accessly/permitted_actions/query.rb', line 7 def initialize(actors, segment_id) super(actors, segment_id) end |
Instance Method Details
#can?(action_id, object_type) ⇒ Boolean
Ask whether the actor has permission to perform action_id in the given namespace. Multiple actions can have the same id as long as their namespace is different. The namespace can be any String. We recommend using namespace to group a class of permissions, such as to group parts of a particular feature in your application.
Lookups are cached in the object to prevent redundant database calls.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/accessly/permitted_actions/query.rb', line 30 def can?(action_id, object_type) find_or_set_value(action_id, object_type) do Accessly::QueryBuilder.with_actors(Accessly::PermittedAction, @actors) .where( segment_id: @segment_id, action: action_id, object_type: String(object_type), ).exists? end end |