Class: DecisionAgent::Auth::RbacConfig
- Inherits:
-
Object
- Object
- DecisionAgent::Auth::RbacConfig
- Defined in:
- lib/decision_agent/auth/rbac_config.rb
Overview
Configuration class for RBAC adapter
Instance Attribute Summary collapse
-
#authenticator ⇒ Object
Returns the value of attribute authenticator.
-
#user_store ⇒ Object
Returns the value of attribute user_store.
Instance Method Summary collapse
-
#adapter ⇒ Object
Get the configured adapter, or return default if none configured.
-
#adapter=(adapter_instance) ⇒ Object
Configure with a custom adapter instance.
-
#configured? ⇒ Boolean
Check if an adapter has been configured.
-
#initialize ⇒ RbacConfig
constructor
A new instance of RbacConfig.
-
#use(adapter_type, **options) ⇒ Object
Configure with a built-in adapter.
Constructor Details
#initialize ⇒ RbacConfig
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
#authenticator ⇒ Object
Returns the value of attribute authenticator.
7 8 9 |
# File 'lib/decision_agent/auth/rbac_config.rb', line 7 def authenticator @authenticator end |
#user_store ⇒ Object
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
#adapter ⇒ Object
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
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
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
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, **) case adapter_type.to_sym when :default @adapter = DefaultAdapter.new when :devise_cancan @adapter = DeviseCanCanAdapter.new(**) when :pundit @adapter = PunditAdapter.new(**) when :custom @adapter = CustomAdapter.new(**) else raise ArgumentError, "Unknown adapter type: #{adapter_type}. Use :default, :devise_cancan, :pundit, or :custom" end self end |