Module: Authority
- Defined in:
- lib/authority.rb,
lib/authority/railtie.rb,
lib/authority/version.rb,
lib/authority/abilities.rb,
lib/authority/authorizer.rb,
lib/authority/controller.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, NoAuthorizerError, Railtie, SecurityViolation
Constant Summary collapse
- VERSION =
"2.4.1"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
-
.abilities ⇒ Hash
NOTE: once this method is called, the library has started meta programming and abilities should no longer be modified.
- .action_authorized?(action, resource, user, options = {}) ⇒ Boolean
-
.adjectives ⇒ Array
Values from adjectives method.
- .configure {|configuration| ... } ⇒ Object
-
.enforce(action, resource, user, options = {}) ⇒ Model
Resource instance.
- .logger ⇒ Object
-
.verbs ⇒ Array
Keys from adjectives method.
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
47 48 49 |
# File 'lib/authority.rb', line 47 def configuration @configuration end |
Class Method Details
.abilities ⇒ Hash
NOTE: once this method is called, the library has started meta programming and abilities should no longer be modified
14 15 16 |
# File 'lib/authority.rb', line 14 def self.abilities configuration.abilities.freeze end |
.action_authorized?(action, resource, user, options = {}) ⇒ Boolean
41 42 43 44 |
# File 'lib/authority.rb', line 41 def self.(action, resource, user, = {}) = [resource, ].tap {|args| args.pop if args.last == {}} user.send("can_#{action}?", *) end |
.adjectives ⇒ Array
Returns values from adjectives method.
24 25 26 |
# File 'lib/authority.rb', line 24 def self.adjectives abilities.values end |
.configure {|configuration| ... } ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/authority.rb', line 50 def self.configure self.configuration ||= Configuration.new yield(configuration) if block_given? configuration end |
.enforce(action, resource, user, options = {}) ⇒ Model
Returns resource instance.
34 35 36 37 38 39 |
# File 'lib/authority.rb', line 34 def self.enforce(action, resource, user, = {}) unless (action, resource, user, ) raise SecurityViolation.new(user, action, resource) end resource end |
.logger ⇒ Object
58 59 60 |
# File 'lib/authority.rb', line 58 def self.logger @logger ||= configuration.logger end |
.verbs ⇒ Array
Returns keys from adjectives method.
19 20 21 |
# File 'lib/authority.rb', line 19 def self.verbs abilities.keys end |