Class: MailRoom::Configuration

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

Overview

Wraps configuration for a set of individual mailboxes with global config

Author:

  • Tony Pitale

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Initialize a new configuration of mailboxes


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mail_room/configuration.rb', line 10

def initialize(options={})
  self.mailboxes = []
  self.quiet = options.fetch(:quiet, false)

  if options.has_key?(:config_path)
    begin
      erb = ERB.new(File.read(options[:config_path]))
      erb.filename = options[:config_path]
      config_file = YAML.load(erb.result)

      set_mailboxes(config_file[:mailboxes])
      set_health_check(config_file[:health_check])
    rescue => e
      raise e unless quiet
    end
  end
end

Instance Attribute Details

#health_checkObject

Returns the value of attribute health_check.


7
8
9
# File 'lib/mail_room/configuration.rb', line 7

def health_check
  @health_check
end

#log_pathObject

Returns the value of attribute log_path.


7
8
9
# File 'lib/mail_room/configuration.rb', line 7

def log_path
  @log_path
end

#mailboxesObject

Returns the value of attribute mailboxes.


7
8
9
# File 'lib/mail_room/configuration.rb', line 7

def mailboxes
  @mailboxes
end

#quietObject

Returns the value of attribute quiet.


7
8
9
# File 'lib/mail_room/configuration.rb', line 7

def quiet
  @quiet
end

Instance Method Details

#set_health_check(health_check_config) ⇒ Object

Builds the health checker from YAML configuration

Parameters:

  • health_check_config

    nil or a Hash containing :address and :port


40
41
42
43
44
# File 'lib/mail_room/configuration.rb', line 40

def set_health_check(health_check_config)
  return unless health_check_config

  self.health_check = HealthCheck.new(health_check_config)
end

#set_mailboxes(mailboxes_config) ⇒ Object

Builds individual mailboxes from YAML configuration

Parameters:

  • mailboxes_config

31
32
33
34
35
# File 'lib/mail_room/configuration.rb', line 31

def set_mailboxes(mailboxes_config)
  mailboxes_config.each do |attributes|
    self.mailboxes << Mailbox.new(attributes)
  end
end