aboutsummaryrefslogblamecommitdiffstats
path: root/activemodel/lib/active_model/mass_assignment_security/permission_set.rb
blob: 9fcb94d48ac6e51339613e3e2563b7e936b12a9f (plain) (tree)
1
2
3
4
5
6
7
8
9
             
                                                         
 
                  
                               
                             

                           
                   






                                            
             
 


                                       







                                   







                                   
       
     
   
require 'set'
require 'active_model/mass_assignment_security/sanitizer'

module ActiveModel
  module MassAssignmentSecurity
    class PermissionSet < Set
      attr_accessor :logger

      def +(values)
        super(values.map(&:to_s))
      end

      def include?(key)
        super(remove_multiparameter_id(key))
      end

    protected

      def remove_multiparameter_id(key)
        key.to_s.gsub(/\(.+/, '')
      end
    end

    class WhiteList < PermissionSet
      include Sanitizer

      def deny?(key)
        !include?(key)
      end
    end

    class BlackList < PermissionSet
      include Sanitizer

      def deny?(key)
        include?(key)
      end
    end
  end
end