Class: Toggly::Rails::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_idsObject

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_keyObject

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_versionObject

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_urlObject

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_prefixString

Returns Cache key prefix for Rails.cache.

Returns:

  • (String)

    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_builderProc?

Returns Custom context builder proc.

Returns:

  • (Proc, nil)

    Custom context builder proc



20
21
22
# File 'lib/toggly/rails/configuration.rb', line 20

def context_builder
  @context_builder
end

#defaultsObject

Core configuration options (delegated to Toggly::Config)



11
12
13
# File 'lib/toggly/rails/configuration.rb', line 11

def defaults
  @defaults
end

#definitions_urlObject

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_refreshObject

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_devObject

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

#environmentObject

Core configuration options (delegated to Toggly::Config)



11
12
13
# File 'lib/toggly/rails/configuration.rb', line 11

def environment
  @environment
end

#groups_methodSymbol

Returns Method to call on current_user for groups.

Returns:

  • (Symbol)

    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_timeoutObject

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_methodSymbol

Returns Method to call on current_user for identity.

Returns:

  • (Symbol)

    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_nameObject

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_intervalObject

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_enabledBoolean

Returns Enable request-scoped context (via middleware).

Returns:

  • (Boolean)

    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_providerObject

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_extractorsHash<Symbol, Proc>

Returns Custom trait extractors.

Returns:

  • (Hash<Symbol, Proc>)

    Custom trait extractors



32
33
34
# File 'lib/toggly/rails/configuration.rb', line 32

def trait_extractors
  @trait_extractors
end

#use_rails_cacheBoolean

Returns Use Rails.cache as snapshot provider.

Returns:

  • (Boolean)

    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_definitionsObject

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

Parameters:

  • name (Symbol)

    Trait name

Yields:

  • (request, user)

    Block that returns the trait value



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

Parameters:

  • config (Toggly::Config)


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