Class: ActionAuthorizer::Base
- Inherits:
-
Object
- Object
- ActionAuthorizer::Base
- Defined in:
- lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .authorized?(current_user, controller, action, params) ⇒ Boolean
- .skip_authentication(only: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(current_user, params) ⇒ Base
constructor
A new instance of Base.
- #skip?(action) ⇒ Boolean
Constructor Details
#initialize(current_user, params) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 6 def initialize(current_user, params) @current_user = current_user @params = params end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
4 5 6 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 4 def current_user @current_user end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 4 def params @params end |
Class Method Details
.authorized?(current_user, controller, action, params) ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 16 def (current_user, controller, action, params) = "#{controller}_authorizer".classify.constantize.new(current_user, params) result = (.skip?(action) || !!current_user&.persisted?) && .respond_to?(action.to_sym) && .send(action.to_sym) raise ActionAuthorizer::ResultError.new(result) if [true, false].exclude?(result) result end |
.skip_authentication(only: nil) ⇒ Object
23 24 25 26 27 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 23 def skip_authentication(only: nil) define_method(:skip?) do |action| only.blank? || [only].compact.flatten.map!(&:to_sym).include?(action.to_sym) end end |
Instance Method Details
#skip?(action) ⇒ Boolean
11 12 13 |
# File 'lib/generators/action_authorizer/install/templates/app/authorizers/action_authorizer/base.rb', line 11 def skip?(action) false end |