Class: RocketJob::Config

Inherits:
Object
  • Object
show all
Includes:
Plugins::Document
Defined in:
lib/rocket_job/config.rb

Overview

Centralized Configuration for Rocket Jobs

Class Method Summary collapse

Class Method Details

.instanceObject

Returns the single instance of the Rocket Job Configuration for this site in a thread-safe way



9
10
11
12
13
14
15
16
# File 'lib/rocket_job/config.rb', line 9

def self.instance
  @instance ||= begin
    first || create
  rescue StandardError
    # In case another process has already created the first document
    first
  end
end

.load!(environment = 'development', file_name = nil, encryption_file_name = nil) ⇒ Object

Configure Mongoid

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rocket_job/config.rb', line 52

def self.load!(environment = 'development', file_name = nil, encryption_file_name = nil)
  config_file = file_name ? Pathname.new(file_name) : Pathname.pwd.join('config/mongoid.yml')

  raise(ArgumentError, "Mongo Configuration file: #{config_file} not found") unless config_file.file?

  logger.debug "Reading Mongo configuration from: #{config_file}"
  ::Mongoid.load!(config_file, environment)

  # Load Encryption configuration file if present
  return unless defined?(SymmetricEncryption)

  config_file =
    if encryption_file_name
      Pathname.new(encryption_file_name)
    else
      Pathname.pwd.join('config/symmetric-encryption.yml')
    end

  return unless config_file.file?

  logger.debug "Reading SymmetricEncryption configuration from: #{config_file}"
  SymmetricEncryption.load!(config_file.to_s, environment)
end