Sha256: a3f2ac763935d5fb9e051af875ee2eef73e9d72b5cec2d974084c5eb8b62f23d

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

module Devise
  class BaseSanitizer
    attr_reader :params, :resource_name, :resource_class

    def initialize(resource_class, resource_name, params)
      @resource_class = resource_class
      @resource_name  = resource_name
      @params         = params
      @blocks         = Hash.new
    end

    def for(kind, &block)
      if block_given?
        @blocks[kind] = block
      else
        block = @blocks[kind]
        block ? block.call(default_params) : fallback_for(kind)
      end
    end

    private

    def fallback_for(kind)
      default_params
    end

    def default_params
      params.fetch(resource_name, {})
    end
  end

  class ParameterSanitizer < BaseSanitizer
    private

    def fallback_for(kind)
      if respond_to?(kind, true)
        send(kind)
      else
        raise NotImplementedError, "Devise Parameter Sanitizer doesn't know how to sanitize parameters for #{kind}"
      end
    end

    def sign_in
      default_params.permit(*auth_keys)
    end

    def sign_up
      default_params.permit(*(auth_keys + [:password, :password_confirmation]))
    end

    def account_update
      default_params.permit(*(auth_keys + [:password, :password_confirmation, :current_password]))
    end

    def auth_keys
      resource_class.authentication_keys
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loyal_devise-2.1.7 lib/devise/parameter_sanitizer.rb
loyal_devise-2.1.6 lib/devise/parameter_sanitizer.rb
loyal_devise-2.1.5 lib/devise/parameter_sanitizer.rb
loyal_devise-2.1.4 lib/devise/parameter_sanitizer.rb
loyal_devise-2.1.3 lib/devise/parameter_sanitizer.rb