class Wallaby::ModelAuthorizer
This is the base authorizer class to provider authorization for given/associated model.
For best practice, please create an application authorizer class (see example) to better control the functions shared between different model authorizers. @example Create an application class for Admin Interface usage
class Admin::ApplicationAuthorizer < Wallaby::ModelAuthorizer base_class! end
@since wallaby-5.2.0
Attributes
@!attribute [w] provider_name
@!attribute [r] context @return [ActionController::Base, ActionView::Base] @since 0.2.2
@!attribute [r] model_class
@return [Class]
@!attribute [r] options @return [Hash] @since 0.2.2
@!attribute [r] provider @return [Wallaby::ModelAuthorizationProvider] the instance that does the job @since wallaby-5.2.0
Public Class Methods
@param model_class
[Class] @param context [ActionController::Base, ActionView::Base] @param options [Symbol, String, nil]
# File lib/authorizers/wallaby/model_authorizer.rb, line 54 def initialize(model_class, context, **options) @model_class = model_class || self.class.model_class @context = context @options = options @provider = guess_provider_from(context) end
@!attribute [r] provider_name
Provider name of the authorization framework used. It will be inherited from its parent classes if there isn't one for current class. @return [String, Symbol]
# File lib/authorizers/wallaby/model_authorizer.rb, line 25 def provider_name @provider_name ||= superclass.try :provider_name end
Protected Instance Methods
Go through the provider list and find out the one is {Wallaby::ModelAuthorizationProvider.available? .available?} @param context [ActionController::Base, ActionView::Base]
# File lib/authorizers/wallaby/model_authorizer.rb, line 66 def guess_provider_from(context) provider_class = Map.authorizer_provider_map(model_class).try do |providers| providers[options[:provider_name] || self.class.provider_name] \ || providers.values.find { |klass| klass.available? context } \ || providers[:default] # fallback to default end provider_class.new context, options end