class ActionAuthorization::ActiveRecord::Base
This class contains all the patches to ActiveRecord::Base
that make this library function on the model side. You should only have to interact with these methods on concrete models and not by interacting with ActiveRecord::Base
directly.
Public Class Methods
Defines an authorization rule for the specified action names. If multiple names are passed, then the same rule will be used for all of them.
Action names should take the following format “controller_name#action_name”. E.G. To specify a rule for the update action on the posts controller, you would write 'posts#update'.
names can also be symbols.
@param *names [String, Symbol] The names of the actions which will use
the given block for authorization.
@param &block [Proc] The code to run on an authorization check.
# File lib/authorizer/active_record_patch.rb, line 42 def self.define_rule(*names, &block) perms = self.get_perms names.each {|name| perms[name.to_sym] = block} end
returns the hash mapping permission rules to executable actions. This is used internally and should not need to be called directly by the user.
# File lib/authorizer/active_record_patch.rb, line 13 def self.get_perms unless (self.class_variables.include?(:'@@perms')) @@perms = {} end init_fallback_rule return @@perms end
Ensures that the fallback_rule
class variable is defined. Used internally. There should be no need for users to call this method directly.
# File lib/authorizer/active_record_patch.rb, line 24 def self.init_fallback_rule @@fallback_rule = nil unless (self.class_variable_defined?(:@@fallback_rule)) end
Defines a fallback rule. The fallback rule defined by this class method will be used in every case where a permission rule is not specified. This is intended to be used in situations where users wish to define some generic authorization check that will be run for every action that doesn't have its own rule specified.
@param &rule [Proc] The code to run when a rule is not defined for any action.
# File lib/authorizer/active_record_patch.rb, line 55 def self.set_fallback_rule(&rule) @@fallback_rule = rule end