Module: Authority

Defined in:
lib/authority.rb,
lib/authority/railtie.rb,
lib/authority/version.rb,
lib/authority/abilities.rb,
lib/authority/controller.rb,
lib/authority/authorizer.rb,
lib/authority/configuration.rb,
lib/authority/user_abilities.rb,
lib/authority/security_violation.rb,
lib/generators/authority/install_generator.rb

Defined Under Namespace

Modules: Abilities, Controller, Generators, UserAbilities Classes: Authorizer, Configuration, MissingUser, NoAuthorizerError, Railtie, SecurityViolation

Constant Summary

VERSION =
"3.0.0"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) configuration

Returns the value of attribute configuration



49
50
51
# File 'lib/authority.rb', line 49

def configuration
  @configuration
end

Class Method Details

+ (Hash) abilities

NOTE: once this method is called, the library has started meta programming and abilities should no longer be modified



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

def self.abilities
  configuration.abilities.freeze
end

+ (Boolean) action_authorized?(action, resource, user, options = {})

Raises:



42
43
44
45
46
# File 'lib/authority.rb', line 42

def self.action_authorized?(action, resource, user, options = {})
  raise MissingUser if user.nil?
  resource_and_maybe_options = [resource, options].tap {|args| args.pop if args.last == {}}
  user.send("can_#{action}?", *resource_and_maybe_options)
end

+ (Array) adjectives



26
27
28
# File 'lib/authority.rb', line 26

def self.adjectives
  abilities.values
end

+ (Object) configure {|configuration| ... }

Yields:



52
53
54
55
56
57
58
# File 'lib/authority.rb', line 52

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
  require_authority_internals!

  configuration
end

+ (Model) enforce(action, resource, user, options = {})

Returns resource instance

Raises:



36
37
38
39
40
# File 'lib/authority.rb', line 36

def self.enforce(action, resource, user, options = {})
  unless action_authorized?(action, resource, user, options)
    raise SecurityViolation.new(user, action, resource)
  end
end

+ (Object) logger



60
61
62
# File 'lib/authority.rb', line 60

def self.logger
  @logger ||= configuration.logger
end

+ (Array) verbs



21
22
23
# File 'lib/authority.rb', line 21

def self.verbs
  abilities.keys
end