Class: ConfigService

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

Class Method Summary collapse

Class Method Details

.environmentObject



22
23
24
25
26
27
28
# File 'lib/services/config_service.rb', line 22

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

.load_config(config_file_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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
  ['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
  
  raise("You must have the file #{config_file_name} in either 'conf' or 'config' directory of your application") unless config_file

  YAML.load_file(config_file)
end