Class: MailEngine::Configuration

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

Overview

Load configure file from config/mail_engine_config.yml you can access the config by MailEngine::Base.current_config[]

Class Method Summary collapse

Class Method Details

.config_checkObject

Need check below config options

log_mail: true user_class_name: ‘User’ user_locale_column: ‘locale’ mount_at: ‘/admin/mail_engine’ intercept_email: ‘your email’ default_from: ‘you email’ access_check_method: ‘logged_in?’ sendgrid:

sendgrid_user: 'you send grid user'
sendgrid_key: 'you send grid password'
sendgrid_category: 'your send grid category'


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mail_engine/configuration.rb', line 29

def config_check
  if MailEngine::Base.current_config.blank?
    puts "\e[1;31;40m[Mail Engine Warning]\e[0m Not found mail_engine_config.yml, so mail_engine won't be able to work."
    raise ConfigurationError.new("did't find config file at config/mail_engine_config.yml")
  end

  ### if not set them will has some bad news
  # user_locale_column
  # access_check_method

  %w{log_mail user_class_name mount_at default_from}.each do |option|
    raise ConfigurationError.new("Please add :#{option} config into mail_engine_config.yml.") if MailEngine::Base.current_config[option].blank?
  end

  %w{sendgrid_category sendgrid_user sendgrid_key}.each do |option|
    raise ConfigurationError.new("Please add :#{option} config under not :sendgrid into mail_engine_config.yml.") if MailEngine::Base.current_config["sendgrid"][option].blank?
  end
rescue ConfigurationError => e
  puts <<-NOTE
\e[1;31;40m[Mail Engine Warning - Below is a sample config]\e[0m
===============================================
  log_mail: true
  user_class_name: 'User'
  user_locale_column: 'locale'
  mount_at: '/admin/mail_engine'
  intercept_email: 'your email'
  default_from: 'you email'
  access_check_method: 'logged_in?'
  sendgrid:
    sendgrid_user: 'you send grid user'
    sendgrid_key: 'you send grid password'
    sendgrid_category: 'your send grid category'
===============================================
  NOTE
end

.load_and_checkObject



7
8
9
10
11
12
13
# File 'lib/mail_engine/configuration.rb', line 7

def load_and_check
  require 'erb' # make config file support erb tags. like <% %>
  config_path = File.join(Rails.root, "config", "mail_engine_config.yml")
  MailEngine::Base.configurations = {}
  MailEngine::Base.configurations = YAML::load(ERB.new(IO.read(config_path)).result) if File.exist?(config_path)
  config_check
end