Sha256: 4b9b681f0d766011d02d815ff3638b57a4eeab4eb8368e1b356ef6ddbbf92585
Contents?: true
Size: 1.04 KB
Versions: 47
Compression:
Stored size: 1.04 KB
Contents
module Avo module Concerns module PolicyHelpers extend ActiveSupport::Concern class_methods do def inherit_association_from_policy(association_name, policy_class) [:create, :edit, :update, :destroy, :show, :reorder, :act_on].each do |method_action| define_policy_method(method_action, association_name, policy_class) end define_policy_method("view", association_name, policy_class, "index") end private # Define a method for the given action and association name. # Call the policy class with the given action passing the user and record. # Example: # def create_team_members? # TeamMemberPolicy.new(user, record).create? # end def define_policy_method(method_action, association_name, policy_class, policy_action = method_action) define_method "#{method_action}_#{association_name}?" do policy_class.new(user, record).send "#{policy_action}?" end end end end end end
Version data entries
47 entries across 47 versions & 1 rubygems