configerator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/configerator.rb +8 -5
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f6252318d5dc6d903f22526000b7e017fa8c88c
4
- data.tar.gz: 122ecf1a995d4195f8ecf5cc9f8ee33f495fc09d
3
+ metadata.gz: adbb2b382aa1b45e54678f1f704565bd0161da27
4
+ data.tar.gz: 04597f001baaf1db15a3d3f0b233979b07695c52
5
5
  SHA512:
6
- metadata.gz: 3d0558904733988bb80c710ae283bceb996315dc4c75351cb90f26b7ba554ea63ac48521af484fca9b911ba3d6f53fdf9bef686b131e2ee86f04f8b1b38bc566
7
- data.tar.gz: 03c473376629c211a2dbca0e1243d3850679e44330336920020346be287283cca68dd881e58e27a37af45bbddef887cd71de18861f04062e54628a787c9572da
6
+ metadata.gz: ca11055b43377f1593ee3d9d468a32a144c8ae676cd5c7e49fdce76393be719ed5a7c1a7e4aabcdb578cd034430bfa6ad2c0fba8767c0d9fdcb4c4af18d8c71a
7
+ data.tar.gz: 2c0839d61a3ef419dbad6101ec38598389966d93b49ba686169dd87fb6a0cb80bb2f5b08152c7eed9d5b2edca46723ce0a09c0b94fa8cb682608be46cb19efe6
@@ -1,9 +1,12 @@
1
1
  require 'uri'
2
2
 
3
3
  module Configerator
4
- def required(name, method=nil)
5
- value = cast(ENV.fetch(name.to_s.upcase), method)
6
- create(name, value)
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} end", __FILE__, __LINE__
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.1
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-05 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Simple web application extension for configuring applications from the
14
- environment, following the 12factor pattern.
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: []