Class: MetalArchives::Configuration
- Inherits:
-
Object
- Object
- MetalArchives::Configuration
- Defined in:
- lib/metal_archives/configuration.rb
Overview
Contains configuration options
Instance Attribute Summary collapse
-
#app_contact ⇒ Object
Required. Application contact email (used in request header).
-
#app_name ⇒ Object
Required. Application name (used in request header).
-
#app_version ⇒ Object
Required. Application version (used in request header).
-
#cache_options ⇒ Object
Cache strategy options.
-
#cache_strategy ⇒ Object
Cache strategy.
-
#endpoint ⇒ Object
Override Metal Archives endpoint (defaults to www.metal-archives.com/).
-
#endpoint_password ⇒ Object
Returns the value of attribute endpoint_password.
-
#endpoint_user ⇒ Object
Endpoint HTTP Basic authentication.
-
#logger ⇒ Object
Logger instance.
Instance Method Summary collapse
-
#initialize(**attributes) ⇒ Configuration
constructor
Default configuration values.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize(**attributes) ⇒ Configuration
Default configuration values
56 57 58 59 60 61 62 63 64 |
# File 'lib/metal_archives/configuration.rb', line 56 def initialize(**attributes) attributes.each { |key, value| send(:"#{key}=", value) } @endpoint ||= "https://www.metal-archives.com/" @logger ||= Logger.new $stdout @cache_strategy ||= "memory" @cache_options ||= { size: 100 } end |
Instance Attribute Details
#app_contact ⇒ Object
Required. Application contact email (used in request header)
25 26 27 |
# File 'lib/metal_archives/configuration.rb', line 25 def app_contact @app_contact end |
#app_name ⇒ Object
Required. Application name (used in request header)
15 16 17 |
# File 'lib/metal_archives/configuration.rb', line 15 def app_name @app_name end |
#app_version ⇒ Object
Required. Application version (used in request header)
20 21 22 |
# File 'lib/metal_archives/configuration.rb', line 20 def app_version @app_version end |
#cache_options ⇒ Object
Cache strategy options
51 52 53 |
# File 'lib/metal_archives/configuration.rb', line 51 def @cache_options end |
#cache_strategy ⇒ Object
Cache strategy
46 47 48 |
# File 'lib/metal_archives/configuration.rb', line 46 def cache_strategy @cache_strategy end |
#endpoint ⇒ Object
Override Metal Archives endpoint (defaults to www.metal-archives.com/)
30 31 32 |
# File 'lib/metal_archives/configuration.rb', line 30 def endpoint @endpoint end |
#endpoint_password ⇒ Object
Returns the value of attribute endpoint_password.
36 37 38 |
# File 'lib/metal_archives/configuration.rb', line 36 def endpoint_password @endpoint_password end |
#endpoint_user ⇒ Object
Endpoint HTTP Basic authentication
35 36 37 |
# File 'lib/metal_archives/configuration.rb', line 35 def endpoint_user @endpoint_user end |
#logger ⇒ Object
Logger instance
41 42 43 |
# File 'lib/metal_archives/configuration.rb', line 41 def logger @logger end |
Instance Method Details
#validate! ⇒ Object
Validate configuration
- Raises
-
MetalArchives::Errors::ConfigurationError when configuration is invalid
72 73 74 75 76 77 78 |
# File 'lib/metal_archives/configuration.rb', line 72 def validate! raise Errors::InvalidConfigurationError, "app_name has not been configured" if app_name.blank? raise Errors::InvalidConfigurationError, "app_version has not been configured" if app_version.blank? raise Errors::InvalidConfigurationError, "app_contact has not been configured" if app_contact.blank? raise Errors::InvalidConfigurationError, "cache_strategy has not been configured" if cache_strategy.blank? raise Errors::InvalidConfigurationError, "cache_strategy must be one of: #{CACHE_STRATEGIES.join(', ')}" if CACHE_STRATEGIES.exclude?(cache_strategy.to_s) end |