Class: ContextualConfig::Configuration
- Inherits:
-
Object
- Object
- ContextualConfig::Configuration
- Defined in:
- lib/contextual_config/configuration.rb
Overview
Configuration class for gem-wide settings
Instance Attribute Summary collapse
-
#cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
-
#cache_store ⇒ Object
Returns the value of attribute cache_store.
-
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
-
#default_priority ⇒ Object
Returns the value of attribute default_priority.
-
#enable_logging ⇒ Object
Returns the value of attribute enable_logging.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#timing_evaluation_enabled ⇒ Object
Returns the value of attribute timing_evaluation_enabled.
Instance Method Summary collapse
-
#cache_enabled? ⇒ Boolean
Cache configuration.
- #cache_store_available? ⇒ Boolean
-
#effective_logger ⇒ Object
Get effective logger.
-
#enable_logging? ⇒ Boolean
Logging configuration.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #logger_available? ⇒ Boolean
-
#reset! ⇒ Object
Reset to defaults.
-
#timing_evaluation_enabled? ⇒ Boolean
Timing evaluation configuration.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 |
# File 'lib/contextual_config/configuration.rb', line 11 def initialize @cache_enabled = false @cache_ttl = 300 # 5 minutes in seconds @cache_store = nil @default_priority = 100 @enable_logging = false @logger = nil @timing_evaluation_enabled = true end |
Instance Attribute Details
#cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def cache_enabled @cache_enabled end |
#cache_store ⇒ Object
Returns the value of attribute cache_store.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def cache_store @cache_store end |
#cache_ttl ⇒ Object
Returns the value of attribute cache_ttl.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def cache_ttl @cache_ttl end |
#default_priority ⇒ Object
Returns the value of attribute default_priority.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def default_priority @default_priority end |
#enable_logging ⇒ Object
Returns the value of attribute enable_logging.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def enable_logging @enable_logging end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def logger @logger end |
#timing_evaluation_enabled ⇒ Object
Returns the value of attribute timing_evaluation_enabled.
8 9 10 |
# File 'lib/contextual_config/configuration.rb', line 8 def timing_evaluation_enabled @timing_evaluation_enabled end |
Instance Method Details
#cache_enabled? ⇒ Boolean
Cache configuration
22 23 24 |
# File 'lib/contextual_config/configuration.rb', line 22 def cache_enabled? @cache_enabled && cache_store_available? end |
#cache_store_available? ⇒ Boolean
26 27 28 |
# File 'lib/contextual_config/configuration.rb', line 26 def cache_store_available? @cache_store.respond_to?(:read) && @cache_store.respond_to?(:write) end |
#effective_logger ⇒ Object
Get effective logger
40 41 42 43 44 45 |
# File 'lib/contextual_config/configuration.rb', line 40 def effective_logger return @logger if logger_available? return Rails.logger if defined?(Rails) && Rails.logger Logger.new($stdout) end |
#enable_logging? ⇒ Boolean
Logging configuration
31 32 33 |
# File 'lib/contextual_config/configuration.rb', line 31 def enable_logging? @enable_logging && logger_available? end |
#logger_available? ⇒ Boolean
35 36 37 |
# File 'lib/contextual_config/configuration.rb', line 35 def logger_available? @logger.respond_to?(:info) && @logger.respond_to?(:error) end |
#reset! ⇒ Object
Reset to defaults
66 67 68 |
# File 'lib/contextual_config/configuration.rb', line 66 def reset! initialize end |
#timing_evaluation_enabled? ⇒ Boolean
Timing evaluation configuration
48 49 50 |
# File 'lib/contextual_config/configuration.rb', line 48 def timing_evaluation_enabled? @timing_evaluation_enabled end |
#validate! ⇒ Object
Validate configuration
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/contextual_config/configuration.rb', line 53 def validate! if @cache_enabled && !cache_store_available? raise(ConfigurationError, 'Cache is enabled but cache_store is not properly configured') end raise(ConfigurationError, 'cache_ttl must be a positive number') if cache_ttl <= 0 raise(ConfigurationError, 'default_priority must be non-negative') if default_priority.negative? true end |