Class: Toggly::Rails::Configuration
- Inherits:
-
Object
- Object
- Toggly::Rails::Configuration
- Defined in:
- lib/toggly/rails/configuration.rb
Overview
Rails-specific configuration for Toggly.
Extends the base Toggly configuration with Rails-specific options like context builders and middleware settings.
Instance Attribute Summary collapse
-
#allowed_key_ids ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#app_key ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#app_version ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#base_url ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#cache_key_prefix ⇒ String
Cache key prefix for Rails.cache.
-
#context_builder ⇒ Proc?
Custom context builder proc.
-
#defaults ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#definitions_url ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#disable_background_refresh ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#enable_undefined_in_dev ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#environment ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#groups_method ⇒ Symbol
Method to call on current_user for groups.
-
#http_timeout ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#identity_method ⇒ Symbol
Method to call on current_user for identity.
-
#instance_name ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#refresh_interval ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#request_context_enabled ⇒ Boolean
Enable request-scoped context (via middleware).
-
#snapshot_provider ⇒ Object
Core configuration options (delegated to Toggly::Config).
-
#trait_extractors ⇒ Hash<Symbol, Proc>
Custom trait extractors.
-
#use_rails_cache ⇒ Boolean
Use Rails.cache as snapshot provider.
-
#use_signed_definitions ⇒ Object
Core configuration options (delegated to Toggly::Config).
Instance Method Summary collapse
-
#add_trait(name) {|request, user| ... } ⇒ void
Add a custom trait extractor.
-
#apply_to(config) ⇒ void
Apply this configuration to a Toggly::Config object.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/toggly/rails/configuration.rb', line 40 def initialize # Core defaults @environment = ::Rails.env.production? ? "Production" : "Staging" if defined?(::Rails) @refresh_interval = 300 @http_timeout = 10 @enable_undefined_in_dev = false @disable_background_refresh = false @defaults = {} @use_signed_definitions = false @allowed_key_ids = [] # Rails-specific defaults @request_context_enabled = true @identity_method = :id @groups_method = nil @trait_extractors = {} @use_rails_cache = false @cache_key_prefix = "toggly" end |
Instance Attribute Details
#allowed_key_ids ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def allowed_key_ids @allowed_key_ids end |
#app_key ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def app_key @app_key end |
#app_version ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def app_version @app_version end |
#base_url ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def base_url @base_url end |
#cache_key_prefix ⇒ String
Returns Cache key prefix for Rails.cache.
38 39 40 |
# File 'lib/toggly/rails/configuration.rb', line 38 def cache_key_prefix @cache_key_prefix end |
#context_builder ⇒ Proc?
Returns Custom context builder proc.
20 21 22 |
# File 'lib/toggly/rails/configuration.rb', line 20 def context_builder @context_builder end |
#defaults ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def defaults @defaults end |
#definitions_url ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def definitions_url @definitions_url end |
#disable_background_refresh ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def disable_background_refresh @disable_background_refresh end |
#enable_undefined_in_dev ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def enable_undefined_in_dev @enable_undefined_in_dev end |
#environment ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def environment @environment end |
#groups_method ⇒ Symbol
Returns Method to call on current_user for groups.
29 30 31 |
# File 'lib/toggly/rails/configuration.rb', line 29 def groups_method @groups_method end |
#http_timeout ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def http_timeout @http_timeout end |
#identity_method ⇒ Symbol
Returns Method to call on current_user for identity.
26 27 28 |
# File 'lib/toggly/rails/configuration.rb', line 26 def identity_method @identity_method end |
#instance_name ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def instance_name @instance_name end |
#refresh_interval ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def refresh_interval @refresh_interval end |
#request_context_enabled ⇒ Boolean
Returns Enable request-scoped context (via middleware).
23 24 25 |
# File 'lib/toggly/rails/configuration.rb', line 23 def request_context_enabled @request_context_enabled end |
#snapshot_provider ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def snapshot_provider @snapshot_provider end |
#trait_extractors ⇒ Hash<Symbol, Proc>
Returns Custom trait extractors.
32 33 34 |
# File 'lib/toggly/rails/configuration.rb', line 32 def trait_extractors @trait_extractors end |
#use_rails_cache ⇒ Boolean
Returns Use Rails.cache as snapshot provider.
35 36 37 |
# File 'lib/toggly/rails/configuration.rb', line 35 def use_rails_cache @use_rails_cache end |
#use_signed_definitions ⇒ Object
Core configuration options (delegated to Toggly::Config)
11 12 13 |
# File 'lib/toggly/rails/configuration.rb', line 11 def use_signed_definitions @use_signed_definitions end |
Instance Method Details
#add_trait(name) {|request, user| ... } ⇒ void
This method returns an undefined value.
Add a custom trait extractor
91 92 93 |
# File 'lib/toggly/rails/configuration.rb', line 91 def add_trait(name, &block) @trait_extractors[name.to_sym] = block end |
#apply_to(config) ⇒ void
This method returns an undefined value.
Apply this configuration to a Toggly::Config object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/toggly/rails/configuration.rb', line 64 def apply_to(config) config.app_key = app_key config.environment = environment config.base_url = base_url if base_url config.definitions_url = definitions_url if definitions_url config.refresh_interval = refresh_interval config.http_timeout = http_timeout config.enable_undefined_in_dev = enable_undefined_in_dev config.disable_background_refresh = disable_background_refresh config.app_version = app_version if app_version config.instance_name = instance_name if instance_name config.defaults = defaults config.use_signed_definitions = use_signed_definitions config.allowed_key_ids = allowed_key_ids # Set up snapshot provider config.snapshot_provider = build_snapshot_provider # Use Rails logger config.logger = ::Rails.logger if defined?(::Rails) end |