Class: Pundit::Matchers::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pundit/matchers.rb

Overview

Configuration class for Pundit Matchers.

Constant Summary collapse

DEFAULT_USER_ALIAS =

The default user object value

:user

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



38
39
40
41
# File 'lib/pundit/matchers.rb', line 38

def initialize
  @default_user_alias = DEFAULT_USER_ALIAS
  @user_aliases = {}
end

Instance Attribute Details

#default_user_aliasSymbol|String

The default user object in policies.

Returns:

  • (Symbol|String)


28
29
30
# File 'lib/pundit/matchers.rb', line 28

def default_user_alias
  @default_user_alias
end

#user_aliasesHash

Policy-specific user objects.

Examples:

Use :client as user alias for class Post

config.user_aliases = { 'Post' => :client }

Returns:

  • (Hash)


36
37
38
# File 'lib/pundit/matchers.rb', line 36

def user_aliases
  @user_aliases
end

Instance Method Details

#user_alias(policy) ⇒ Symbol

Returns the user object for the given policy.

Returns:

  • (Symbol)


46
47
48
# File 'lib/pundit/matchers.rb', line 46

def user_alias(policy)
  user_aliases.fetch(policy.class.name, default_user_alias)
end