Class: Mnemosyne::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Configuration

Returns a new instance of Configuration.

Raises:

  • (ArgumentError)


16
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
# File 'lib/mnemosyne/configuration.rb', line 16

def initialize(config)
  @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

  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

#amqpObject (readonly)

Returns the value of attribute amqp.



12
13
14
# File 'lib/mnemosyne/configuration.rb', line 12

def amqp
  @amqp
end

#applicationObject (readonly)

Returns the value of attribute application.



9
10
11
# File 'lib/mnemosyne/configuration.rb', line 9

def application
  @application
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



13
14
15
# File 'lib/mnemosyne/configuration.rb', line 13

def exchange
  @exchange
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



10
11
12
# File 'lib/mnemosyne/configuration.rb', line 10

def hostname
  @hostname
end

#platformObject (readonly)

Returns the value of attribute platform.



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

def platform
  @platform
end

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/mnemosyne/configuration.rb', line 14

def server
  @server
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mnemosyne/configuration.rb', line 45

def enabled?
  @enabled
end