Class: Mnemosyne::Configuration
- Inherits:
-
Object
- Object
- Mnemosyne::Configuration
- Defined in:
- lib/mnemosyne/configuration.rb
Instance Attribute Summary collapse
-
#amqp ⇒ Object
readonly
Returns the value of attribute amqp.
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(config) ⇒ Configuration
constructor
rubocop:disable AbcSize.
Constructor Details
#initialize(config) ⇒ Configuration
rubocop:disable AbcSize
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mnemosyne/configuration.rb', line 17 def initialize(config) # rubocop:disable AbcSize @platform = config.fetch('platform', 'default').to_s.strip.freeze @application = config.fetch('application', nil).to_s.strip.freeze @enabled = config.fetch('enabled', true) @exchange = config.fetch('exchange', 'mnemosyne').to_s.freeze @logger = config.fetch('logger') { Logger.new(STDOUT) } hostname = config.fetch('hostname') { default_hostname } @hostname = hostname.to_s.strip.freeze server = config.fetch('server', 'amqp://localhost') @amqp = AMQ::Settings.configure(server).freeze @server = make_amqp_uri(@amqp).to_s.freeze raise ArgumentError.new 'Platform is required' if platform.blank? if @platform =~ /[^a-zA-Z0-9\-]/ raise ArgumentError.new \ 'Platform may only contain alphanumeric characters' end unless @platform =~ /\A[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*\z/ raise ArgumentError.new \ 'Platform must start and end with a alphanumeric characters' end raise ArgumentError.new('Application is required') if application.blank? raise ArgumentError.new('Hostname is required') if hostname.blank? end |
Instance Attribute Details
#amqp ⇒ Object (readonly)
Returns the value of attribute amqp.
12 13 14 |
# File 'lib/mnemosyne/configuration.rb', line 12 def amqp @amqp end |
#application ⇒ Object (readonly)
Returns the value of attribute application.
9 10 11 |
# File 'lib/mnemosyne/configuration.rb', line 9 def application @application end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
13 14 15 |
# File 'lib/mnemosyne/configuration.rb', line 13 def exchange @exchange end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
10 11 12 |
# File 'lib/mnemosyne/configuration.rb', line 10 def hostname @hostname end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/mnemosyne/configuration.rb', line 14 def logger @logger end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
11 12 13 |
# File 'lib/mnemosyne/configuration.rb', line 11 def platform @platform end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
15 16 17 |
# File 'lib/mnemosyne/configuration.rb', line 15 def server @server end |
Instance Method Details
#enabled? ⇒ Boolean
47 48 49 |
# File 'lib/mnemosyne/configuration.rb', line 47 def enabled? @enabled end |