Class: MetalArchives::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/metal_archives/configuration.rb

Overview

Contains configuration options

Instance Attribute Summary collapse

Instance Method Summary collapse

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_contactObject

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_nameObject

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_versionObject

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_optionsObject

Cache strategy options



51
52
53
# File 'lib/metal_archives/configuration.rb', line 51

def cache_options
  @cache_options
end

#cache_strategyObject

Cache strategy



46
47
48
# File 'lib/metal_archives/configuration.rb', line 46

def cache_strategy
  @cache_strategy
end

#endpointObject

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_passwordObject

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_userObject

Endpoint HTTP Basic authentication



35
36
37
# File 'lib/metal_archives/configuration.rb', line 35

def endpoint_user
  @endpoint_user
end

#loggerObject

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