Class: DecisionAgent::Auth::RbacConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/auth/rbac_config.rb

Overview

Configuration class for RBAC adapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRbacConfig

Returns a new instance of RbacConfig.



9
10
11
12
13
# File 'lib/decision_agent/auth/rbac_config.rb', line 9

def initialize
  @adapter = nil
  @authenticator = nil
  @user_store = nil
end

Instance Attribute Details

#authenticatorObject

Returns the value of attribute authenticator.



7
8
9
# File 'lib/decision_agent/auth/rbac_config.rb', line 7

def authenticator
  @authenticator
end

#user_storeObject

Returns the value of attribute user_store.



7
8
9
# File 'lib/decision_agent/auth/rbac_config.rb', line 7

def user_store
  @user_store
end

Instance Method Details

#adapterObject

Get the configured adapter, or return default if none configured



43
44
45
# File 'lib/decision_agent/auth/rbac_config.rb', line 43

def adapter
  @adapter || DefaultAdapter.new
end

#adapter=(adapter_instance) ⇒ Object

Configure with a custom adapter instance

Parameters:

  • adapter_instance (RbacAdapter)

    An instance of RbacAdapter or subclass

Raises:

  • (ArgumentError)


36
37
38
39
40
# File 'lib/decision_agent/auth/rbac_config.rb', line 36

def adapter=(adapter_instance)
  raise ArgumentError, "Adapter must be an instance of DecisionAgent::Auth::RbacAdapter" unless adapter_instance.is_a?(RbacAdapter)

  @adapter = adapter_instance
end

#configured?Boolean

Check if an adapter has been configured

Returns:

  • (Boolean)


48
49
50
# File 'lib/decision_agent/auth/rbac_config.rb', line 48

def configured?
  !@adapter.nil?
end

#use(adapter_type, **options) ⇒ Object

Configure with a built-in adapter

Parameters:

  • adapter_type (Symbol)

    :default, :devise_cancan, :pundit, or :custom

  • options (Hash)

    Options for the adapter



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/decision_agent/auth/rbac_config.rb', line 18

def use(adapter_type, **options)
  case adapter_type.to_sym
  when :default
    @adapter = DefaultAdapter.new
  when :devise_cancan
    @adapter = DeviseCanCanAdapter.new(**options)
  when :pundit
    @adapter = PunditAdapter.new(**options)
  when :custom
    @adapter = CustomAdapter.new(**options)
  else
    raise ArgumentError, "Unknown adapter type: #{adapter_type}. Use :default, :devise_cancan, :pundit, or :custom"
  end
  self
end