Class: CommandDeck::Configuration
- Inherits:
-
Object
- Object
- CommandDeck::Configuration
- Defined in:
- lib/command_deck/configuration.rb
Overview
Configuration for Command Deck
Example usage in an initializer:
# config/initializers/command_deck.rb
CommandDeck.configure do |config|
config.context_provider = ->(request) do
{
current_user: request.env['warden']&.user,
session: request.session
}
end
end
Instance Attribute Summary collapse
-
#context_provider ⇒ Object
A proc that receives the ActionDispatch::Request and returns a hash to be passed as the
ctxparameter in perform blocks.
Instance Method Summary collapse
-
#build_context(request) ⇒ Hash
Builds the context hash from the given request.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
29 30 31 |
# File 'lib/command_deck/configuration.rb', line 29 def initialize @context_provider = ->(_request) { {} } end |
Instance Attribute Details
#context_provider ⇒ Object
A proc that receives the ActionDispatch::Request and returns a hash to be passed as the ctx parameter in perform blocks.
27 28 29 |
# File 'lib/command_deck/configuration.rb', line 27 def context_provider @context_provider end |
Instance Method Details
#build_context(request) ⇒ Hash
Builds the context hash from the given request
37 38 39 40 41 42 43 44 |
# File 'lib/command_deck/configuration.rb', line 37 def build_context(request) return {} unless context_provider.respond_to?(:call) context_provider.call(request) || {} rescue StandardError => e Rails.logger.warn "[CommandDeck] Context provider error: #{e.}" if defined?(Rails) {} end |