Class: Authority::Authorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/authority/authorizer.rb

Direct Known Subclasses

ApplicationAuthorizer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Authorizer

Returns a new instance of Authorizer.



12
13
14
# File 'lib/authority/authorizer.rb', line 12

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

The base Authorizer class, from which all the authorizers in an app will descend. Provides the authorizer with both class and instance methods like ‘updatable_by?(user)`. Exactly which methods get defined is determined from `config.abilities`; the class is evaluated after any user-supplied config block is run in order to make that possible.



10
11
12
# File 'lib/authority/authorizer.rb', line 10

def resource
  @resource
end

Class Method Details

.default(adjective, user, options = {}) ⇒ Object

Whitelisting approach: anything not specified will be forbidden



17
18
19
# File 'lib/authority/authorizer.rb', line 17

def self.default(adjective, user, options = {})
  false
end

Instance Method Details

#default(adjective, user, options = {}) ⇒ Object

the instance default method calls the class default method



22
23
24
25
# File 'lib/authority/authorizer.rb', line 22

def default(adjective, user, options = {})
  user_and_maybe_options = self.class.send(:user_and_maybe_options, user, options)
  self.class.send(:"#{adjective}_by?", *user_and_maybe_options)
end