Sha256: c58b99af0ec5ceb52e235afd7042e2f2128e830d82233a287d5a5be120b5e173

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

module Protector
  module ActiveRecord
    module StrongParameters
      def self.sanitize!(args, is_new, meta)
        return if args[0].permitted?
        if is_new
          args[0] = args[0].permit(*meta.access[:create].keys) if meta.access.include? :create
        else
          args[0] = args[0].permit(*meta.access[:update].keys) if meta.access.include? :update
        end
      end

      # strong_parameters integration
      def sanitize_for_mass_assignment(*args)
        # We check only for updation here since the creation will be handled by relation
        # (see Protector::Adapters::ActiveRecord::Relation#new_with_protector)
        if Protector.config.strong_parameters? && args.first.respond_to?(:permit) \
            && !new_record? && protector_subject?

          StrongParameters.sanitize! args, false, protector_meta
        end

        super
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
protector-0.7.3 lib/protector/adapters/active_record/strong_parameters.rb
protector-0.7.2 lib/protector/adapters/active_record/strong_parameters.rb
protector-0.7.1 lib/protector/adapters/active_record/strong_parameters.rb