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





                                            
                    
                                                                           

         
             
 


                                       

       
                                            



                      

       
                                            



                     
       
     
   
require 'set'

module ActiveModel
  module MassAssignmentSecurity
    class PermissionSet < Set #:nodoc:

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

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

      def deny?(key)
        raise NotImplementedError, "#deny?(key) supposed to be overwritten"
      end

    protected

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

    class WhiteList < PermissionSet #:nodoc:

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

    class BlackList < PermissionSet #:nodoc:

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