configerator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configerator.rb +8 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adbb2b382aa1b45e54678f1f704565bd0161da27
|
4
|
+
data.tar.gz: 04597f001baaf1db15a3d3f0b233979b07695c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca11055b43377f1593ee3d9d468a32a144c8ae676cd5c7e49fdce76393be719ed5a7c1a7e4aabcdb578cd034430bfa6ad2c0fba8767c0d9fdcb4c4af18d8c71a
|
7
|
+
data.tar.gz: 2c0839d61a3ef419dbad6101ec38598389966d93b49ba686169dd87fb6a0cb80bb2f5b08152c7eed9d5b2edca46723ce0a09c0b94fa8cb682608be46cb19efe6
|
data/lib/configerator.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
3
|
module Configerator
|
4
|
-
def required(name, method=nil)
|
5
|
-
|
6
|
-
|
4
|
+
def required(name, method=nil, error_on_load: true)
|
5
|
+
# Hash#fetch raises a KeyError, Hash#[] doesn't
|
6
|
+
value = error_on_load ? ENV.fetch(name.to_s.upcase) : ENV[name.to_s.upcase]
|
7
|
+
value = cast(value, method)
|
8
|
+
|
9
|
+
create(name, value, error_on_load)
|
7
10
|
end
|
8
11
|
|
9
12
|
def optional(name, method=nil)
|
@@ -60,9 +63,9 @@ module Configerator
|
|
60
63
|
method ? method.call(value) : value
|
61
64
|
end
|
62
65
|
|
63
|
-
def create(name, value)
|
66
|
+
def create(name, value, error_on_load=true)
|
64
67
|
instance_variable_set(:"@#{name}", value)
|
65
|
-
instance_eval "def #{name}; @#{name}
|
68
|
+
instance_eval "def #{name}; @#{name} || (raise \"key not set '#{name}'\" unless #{error_on_load}) end"
|
66
69
|
instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__
|
67
70
|
end
|
68
71
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Mervine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Simple
|
14
|
-
|
13
|
+
description: Simple module for implementing environment based configuration adapted
|
14
|
+
from Pliny and following the 12factor pattern.
|
15
15
|
email: joshua@mervine.net
|
16
16
|
executables: []
|
17
17
|
extensions: []
|