Module: Roadblock::Authorizer
- Defined in:
- lib/roadblock/authorizer.rb
Instance Method Summary collapse
-
#can?(action, object) ⇒ true, false
Returns whether the current auth_object can perform the given action on the provided object.
-
#initialize(auth_object, scopes: []) ⇒ self
Creates an authorizer for the given object and any provided scopes.
Instance Method Details
#can?(action, object) ⇒ true, false
Returns whether the current auth_object can perform the given action on the provided object.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/roadblock/authorizer.rb', line 22 def can?(action, object) if block_given? yield(object) else objects = [*object] objects .map { |obj| send("can_#{action}?", obj) } .all? end end |
#initialize(auth_object, scopes: []) ⇒ self
Creates an authorizer for the given object and any provided scopes.
10 11 12 13 |
# File 'lib/roadblock/authorizer.rb', line 10 def initialize(auth_object, scopes: []) self.auth_object = auth_object self.scopes = scopes end |