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, MissingUser, Railtie, SecurityViolation
Constant Summary collapse
- VERSION =
"3.3.0"
- NoAuthorizerError =
Class.new(RuntimeError)
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.
49 50 51 |
# File 'lib/authority.rb', line 49 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
16 17 18 |
# File 'lib/authority.rb', line 16 def self.abilities configuration.abilities.freeze end |
.action_authorized?(action, resource, user, options = {}) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/authority.rb', line 42 def self.(action, resource, user, = {}) raise MissingUser if user.nil? = [resource, ].tap {|args| args.pop if args.last == {}} user.send("can_#{action}?", *) end |
.adjectives ⇒ Array
Returns values from adjectives method.
26 27 28 |
# File 'lib/authority.rb', line 26 def self.adjectives abilities.values end |
.configure {|configuration| ... } ⇒ Object
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? configuration end |
.enforce(action, resource, user, options = {}) ⇒ Model
Returns resource instance.
36 37 38 39 40 |
# File 'lib/authority.rb', line 36 def self.enforce(action, resource, user, = {}) unless (action, resource, user, ) raise SecurityViolation.new(user, action, resource) end end |
.logger ⇒ Object
60 61 62 |
# File 'lib/authority.rb', line 60 def self.logger configuration.logger end |
.verbs ⇒ Array
Returns keys from adjectives method.
21 22 23 |
# File 'lib/authority.rb', line 21 def self.verbs abilities.keys end |