Class: ViewComponentReducible::Configuration
- Inherits:
-
Object
- Object
- ViewComponentReducible::Configuration
- Defined in:
- lib/view_component_reducible/configuration.rb
Overview
Global configuration for adapter and secrets.
Instance Attribute Summary collapse
- #adapter ⇒ Class
- #redis ⇒ Class
- #redis_namespace ⇒ Class
- #redis_ttl ⇒ Class
- #redis_url ⇒ Class
- #secret ⇒ Class
Instance Method Summary collapse
-
#adapter_for(_controller, adapter_class: nil) ⇒ ViewComponentReducible::Adapter::Base
Build adapter instance for a controller request.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 |
# File 'lib/view_component_reducible/configuration.rb', line 9 def initialize @adapter = Adapter::Session @secret = nil @redis = nil @redis_url = nil @redis_ttl = nil @redis_namespace = nil end |
Instance Attribute Details
#adapter ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def adapter @adapter end |
#redis ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def redis @redis end |
#redis_namespace ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def redis_namespace @redis_namespace end |
#redis_ttl ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def redis_ttl @redis_ttl end |
#redis_url ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def redis_url @redis_url end |
#secret ⇒ Class
7 8 9 |
# File 'lib/view_component_reducible/configuration.rb', line 7 def secret @secret end |
Instance Method Details
#adapter_for(_controller, adapter_class: nil) ⇒ ViewComponentReducible::Adapter::Base
Build adapter instance for a controller request.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/view_component_reducible/configuration.rb', line 22 def adapter_for(_controller, adapter_class: nil) resolved_secret = secret || default_secret raise 'ViewComponentReducible secret is missing' if resolved_secret.nil? kwargs = { secret: resolved_secret } kwargs[:redis] = redis if redis kwargs[:redis_url] = redis_url if redis_url kwargs[:redis_ttl] = redis_ttl unless redis_ttl.nil? kwargs[:redis_namespace] = redis_namespace if redis_namespace (adapter_class || adapter).new(**kwargs) end |