Class: ConfigService

Inherits:
Object
  • Object
show all
Defined in:
lib/services/config_service.rb

Class Method Summary collapse

Class Method Details

.environmentObject



26
27
28
29
30
31
32
33
# File 'lib/services/config_service.rb', line 26

def environment
  return Rails.env if defined? Rails
  return ENV['RACK_ENV'] if ENV['RACK_ENV'].present?
  return ENV['ENV'] if ENV['ENV'].present?
  'development'
rescue => error
  'development'
end

.load_config(config_file_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/services/config_service.rb', line 6

def load_config(config_file_name)
  app_root = (defined? APP_ROOT)? APP_ROOT : File.expand_path('.')

  config_file = nil
  if config_file_name.starts_with?('/')
    config_file = config_file_name if File.exist?(config_file_name)
  else
    ['conf', 'config'].each do |sub_path|
      if File.exist?("#{app_root}/#{sub_path}/#{config_file_name}")
        config_file = "#{app_root}/#{sub_path}/#{config_file_name}"
        break
      end
    end
  end

  raise("#{Time.now.strftime("%m/%d/%Y %H:%M:%S.%3N %z")} ERROR: ConfigService#load_config #{config_file_name} file not found.") unless config_file

  HashUtils.hash_to_open_struct(YAML.load(ERB.new(File.new(config_file).read).result))
end