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
# 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])
    rescue => e
      raise e unless quiet
    end
  end
end

Instance Attribute Details

#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_mailboxes(mailboxes_config) ⇒ Object

Builds individual mailboxes from YAML configuration

Parameters:

  • mailboxes_config

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

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