Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow loading config from CONFIG_JSON env var

  • Loading branch information...
commit 2135f144b5c5f637a74400df6a2e8227b4587b3e 1 parent fe21134
Martyn Loughran authored January 03, 2014

Showing 1 changed file with 18 additions and 4 deletions. Show diff stats Hide diff stats

  1. 22  app.rb
22  app.rb
@@ -4,11 +4,25 @@
4 4
 require 'yaml'
5 5
 require 'json'
6 6
 
  7
+def symbolize(obj)
  8
+  case obj
  9
+  when Hash
  10
+    obj.inject({}) { |mem, (k,v)| mem[k.to_sym] = symbolize(v); mem }
  11
+  else
  12
+    obj
  13
+  end
  14
+end
  15
+
7 16
 class Environment
8 17
   CONFIG = begin
9  
-    YAML.load_file(File.expand_path('../config.yml', __FILE__))
10  
-  rescue Errno::ENOENT
11  
-    raise "Please make sure that a ./config.yml file exists (see .example)"
  18
+    if ENV["CONFIG_JSON"]
  19
+      symbolize JSON.parse(ENV["CONFIG_JSON"])
  20
+    else
  21
+      YAML.load_file(File.expand_path('../config.yml', __FILE__))
  22
+    end
  23
+  rescue => e
  24
+    puts "Config required in a CONFIG_JSON env variable or ./config.yml (see .example)"
  25
+    raise e
12 26
   end
13 27
 
14 28
   attr_reader :name
@@ -19,7 +33,7 @@ def self.list
19 33
 
20 34
   def initialize(name)
21 35
     @name = name
22  
-    env_config = CONFIG[name] || raise("Unknown config")
  36
+    env_config = CONFIG[name.to_sym] || raise("Unknown config")
23 37
 
24 38
     # Default config
25 39
     @config = {

0 notes on commit 2135f14

hi.
by this change, does not load config.yml.example

Martyn Loughran

Good point, fixed in 067ec7a

Please sign in to comment.
Something went wrong with that request. Please try again.