Class: Checkpoint::Query::ActionPermitted

Inherits:
Object
  • Object
show all
Defined in:
lib/checkpoint/query/action_permitted.rb

Overview

ActionPermitted is a predicate query that captures the user, action, and target, and checks if the authority permits the action. It is likely to be the most commonly issued query in any given application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, action, target = Checkpoint::Resource.all, authority: Authority::RejectAll.new) ⇒ ActionPermitted



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/checkpoint/query/action_permitted.rb', line 19

def initialize(
  user,
  action,
  target = Checkpoint::Resource.all,
  authority: Authority::RejectAll.new)

  @user      = user
  @action    = action.to_sym
  @target    = target
  @authority = authority
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def action
  @action
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def target
  @target
end

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/checkpoint/query/action_permitted.rb', line 9

def user
  @user
end

Instance Method Details

#true?Boolean



31
32
33
# File 'lib/checkpoint/query/action_permitted.rb', line 31

def true?
  authority.permits?(user, action, target)
end