configerator 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/configerator.rb +68 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f6252318d5dc6d903f22526000b7e017fa8c88c
|
4
|
+
data.tar.gz: 122ecf1a995d4195f8ecf5cc9f8ee33f495fc09d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d0558904733988bb80c710ae283bceb996315dc4c75351cb90f26b7ba554ea63ac48521af484fca9b911ba3d6f53fdf9bef686b131e2ee86f04f8b1b38bc566
|
7
|
+
data.tar.gz: 03c473376629c211a2dbca0e1243d3850679e44330336920020346be287283cca68dd881e58e27a37af45bbddef887cd71de18861f04062e54628a787c9572da
|
data/lib/configerator.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Configerator
|
4
|
+
def required(name, method=nil)
|
5
|
+
value = cast(ENV.fetch(name.to_s.upcase), method)
|
6
|
+
create(name, value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def optional(name, method=nil)
|
10
|
+
value = cast(ENV[name.to_s.upcase], method)
|
11
|
+
create(name, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def override(name, default, method=nil)
|
15
|
+
value = cast(ENV.fetch(name.to_s.upcase, default), method)
|
16
|
+
create(name, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def int
|
20
|
+
->(v) { v.to_i }
|
21
|
+
end
|
22
|
+
|
23
|
+
def float
|
24
|
+
->(v) { v.to_f }
|
25
|
+
end
|
26
|
+
|
27
|
+
def bool
|
28
|
+
->(v) { v.to_s=='true'}
|
29
|
+
end
|
30
|
+
|
31
|
+
def string
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def symbol
|
36
|
+
->(v) { v.to_sym }
|
37
|
+
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
->(v) { v && URI.parse(v) }
|
41
|
+
end
|
42
|
+
|
43
|
+
# optional :accronyms, array(string)
|
44
|
+
# => ['a', 'b']
|
45
|
+
# optional :numbers, array(int)
|
46
|
+
# => [1, 2]
|
47
|
+
# optional :notype, array
|
48
|
+
# => ['a', 'b']
|
49
|
+
def array(method = nil)
|
50
|
+
-> (v) do
|
51
|
+
if v
|
52
|
+
v.split(',').map{|a| cast(a, method) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def cast(value, method)
|
60
|
+
method ? method.call(value) : value
|
61
|
+
end
|
62
|
+
|
63
|
+
def create(name, value)
|
64
|
+
instance_variable_set(:"@#{name}", value)
|
65
|
+
instance_eval "def #{name}; @#{name} end", __FILE__, __LINE__
|
66
|
+
instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configerator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Mervine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple web application extension for configuring applications from the
|
14
|
+
environment, following the 12factor pattern.
|
15
|
+
email: joshua@mervine.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/configerator.rb
|
21
|
+
homepage: https://github.com/heroku/configerator
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: 'Configerator: A Config Helper'
|
45
|
+
test_files: []
|