envolve 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/Manifest.txt +1 -0
- data/Rakefile +2 -2
- data/lib/envolve.rb +1 -0
- data/lib/envolve/config.rb +12 -6
- data/lib/envolve/error.rb +8 -0
- data/lib/envolve/version.rb +1 -1
- data/test/test_helper.rb +0 -1
- data/test/test_property_config.rb +45 -15
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94e9f25547cce1d320142122f72d7d580f52bd1e
|
4
|
+
data.tar.gz: 3cc94c1b0a79e41cda8dd96d1713077ffcfb73d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30b91a69a0210626901e6a0aa6feb34948e5d97b0c6fa6e488dc7e2ab6f59351eaec3c74c2fb2e7f6008db9d3ebf8e9d391779b7dc11352ee1dd01f1f31717d0
|
7
|
+
data.tar.gz: 58e606ad44024f0752863505c9951ac27d8072973cdc55341288e11d52a4170193165e3ffbf0b1ff5b278bc1fda5c3eb3c2be7b2044dba0f52a4bd4499bf8c64
|
data/HISTORY.md
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -7,9 +7,9 @@ This.email = "jeremy@copiousfreetime.org"
|
|
7
7
|
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
|
8
8
|
|
9
9
|
This.ruby_gemspec do |spec|
|
10
|
-
spec.add_development_dependency( 'rake' , '~> 10.
|
10
|
+
spec.add_development_dependency( 'rake' , '~> 10.4')
|
11
11
|
spec.add_development_dependency( 'minitest' , '~> 5.4' )
|
12
|
-
spec.add_development_dependency( 'rdoc' , '~> 4.
|
12
|
+
spec.add_development_dependency( 'rdoc' , '~> 4.2' )
|
13
13
|
spec.add_development_dependency( 'simplecov', '~> 0.9' )
|
14
14
|
end
|
15
15
|
|
data/lib/envolve.rb
CHANGED
data/lib/envolve/config.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require 'envolve/error'
|
1
2
|
module Envolve
|
2
3
|
# Public: A Configuration class to hold your application configuration
|
3
4
|
#
|
4
5
|
# Feed it ENV or some other Hash-like object and it will allow you to access
|
5
6
|
# the elements in that hash via methods.
|
6
7
|
#
|
7
|
-
# You can also tell it to only pull those items from the initial
|
8
|
+
# You can also tell it to only pull those items from the initial hash that have
|
8
9
|
# a particular prefix, and that prefix will be stripped off of the elements
|
9
10
|
# for access.
|
10
11
|
class Config
|
@@ -50,7 +51,7 @@ module Envolve
|
|
50
51
|
|
51
52
|
# Public: Set a property, with possible transformations
|
52
53
|
#
|
53
|
-
# In the conversion of
|
54
|
+
# In the conversion of the environment to the configuration properties
|
54
55
|
# sometimes the keys and/or values need to be converted to a new name.
|
55
56
|
#
|
56
57
|
# All property transformations take place AFTER the initial keys have been downcased
|
@@ -59,13 +60,16 @@ module Envolve
|
|
59
60
|
# property - the name of the property we want to appear in the configuration
|
60
61
|
# key - the source key from the environment where this property comes from
|
61
62
|
# value - the new value for this property
|
62
|
-
# default - setting a default for this property should
|
63
|
+
# default - setting a default for this property should the environment not
|
64
|
+
# provide a value
|
65
|
+
# required - this property is required to be set via env. If it is not, an
|
66
|
+
# execption is raised when the environment is parsed
|
63
67
|
#
|
64
68
|
# value may also be a lambda, in which ase the lambda is given the original
|
65
69
|
# value and the return value from the labmda is used for the new value.
|
66
70
|
#
|
67
|
-
def self.property( property, key: nil, value: nil, default: nil )
|
68
|
-
properties[property] = { :key => key, :value => value, :default => default }
|
71
|
+
def self.property( property, key: nil, value: nil, default: nil, required: false )
|
72
|
+
properties[property] = { :key => key, :value => value, :default => default, :required => required }
|
69
73
|
end
|
70
74
|
|
71
75
|
# Internal: Return the hash holding the properties
|
@@ -75,7 +79,7 @@ module Envolve
|
|
75
79
|
@_properties ||= Hash.new
|
76
80
|
end
|
77
81
|
|
78
|
-
# Internal: The internal hash holding all the keys and values
|
82
|
+
# Internal: The internal hash like item holding all the keys and values
|
79
83
|
attr_reader :_env
|
80
84
|
|
81
85
|
# Internal: The prefix to strip off all the keys
|
@@ -107,6 +111,7 @@ module Envolve
|
|
107
111
|
|
108
112
|
# Internal: Transform the environment variables to propreties
|
109
113
|
#
|
114
|
+
# Raises MissingPropertyError if the property is required
|
110
115
|
# Returns the transformed hash
|
111
116
|
def transform_properties( env, properties )
|
112
117
|
transformed = env.to_h.dup
|
@@ -117,6 +122,7 @@ module Envolve
|
|
117
122
|
if value = transformed.delete(src_key) then
|
118
123
|
value = apply_transformation(value, trans[:value]) if trans[:value]
|
119
124
|
elsif value.nil? then
|
125
|
+
::Envolve::MissingPropertyError.raise(_prefix, src_key) if trans[:required]
|
120
126
|
value = trans[:default] if trans[:default]
|
121
127
|
end
|
122
128
|
transformed[dest_key] = value
|
data/lib/envolve/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'envolve/config'
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class TestPropertyConfig < ::Minitest::Test
|
5
|
+
class PropertyConfig < ::Envolve::Config
|
6
|
+
environment_source {
|
7
|
+
{
|
8
|
+
'EV_TEST_1' => 'test-1',
|
9
|
+
'EV_TEST_2' => 'test-2',
|
10
|
+
'EV_FOO' => 'test-bar',
|
11
|
+
'EV_WIBBLE' => 'wobble',
|
12
|
+
}
|
11
13
|
}
|
12
|
-
}
|
13
14
|
|
14
|
-
|
15
|
+
prefix 'ev'
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
property 'bar', :key => 'foo'
|
18
|
+
property 'wibble', :value => lambda { |val| val.gsub('o', 'ee') }
|
19
|
+
property 'ara', :default => 42, :value => lambda { |val| Integer(val) }
|
19
20
|
|
20
|
-
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class PropertyMustConfig < ::Envolve::Config
|
24
|
+
property 'envolve_test_must', :required => true
|
25
|
+
end
|
26
|
+
|
27
|
+
class PrefixPropertyMustConfig < ::Envolve::Config
|
28
|
+
prefix 'envolve_test'
|
29
|
+
property 'required_property', :required => true
|
30
|
+
end
|
21
31
|
|
22
|
-
class TestPropertyConfig < ::Minitest::Test
|
23
32
|
def setup
|
24
33
|
@config = PropertyConfig.new
|
25
34
|
end
|
26
35
|
|
27
|
-
|
28
36
|
def test_access_key_as_method
|
29
37
|
assert_equal( 'test-1', @config.test_1 )
|
30
38
|
end
|
@@ -50,4 +58,26 @@ class TestPropertyConfig < ::Minitest::Test
|
|
50
58
|
assert_equal( 42, @config['ara'] )
|
51
59
|
end
|
52
60
|
|
61
|
+
|
62
|
+
def test_required_property
|
63
|
+
assert_raises(::Envolve::MissingPropertyError) {
|
64
|
+
PropertyMustConfig.new
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_required_property_error_message
|
69
|
+
begin
|
70
|
+
PropertyMustConfig.new
|
71
|
+
rescue ::Envolve::MissingPropertyError => e
|
72
|
+
assert_match( /\s+ENVOLVE_TEST_MUST\Z/, e.message )
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_required_property_error_message_includes_prefix
|
77
|
+
begin
|
78
|
+
PrefixPropertyMustConfig.new
|
79
|
+
rescue ::Envolve::MissingPropertyError => e
|
80
|
+
assert_match( /\s+ENVOLVE_TEST_REQUIRED_PROPERTY\Z/, e.message )
|
81
|
+
end
|
82
|
+
end
|
53
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envolve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '10.
|
19
|
+
version: '10.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '10.
|
26
|
+
version: '10.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '4.
|
47
|
+
version: '4.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '4.
|
54
|
+
version: '4.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- lib/envolve.rb
|
88
88
|
- lib/envolve/config.rb
|
89
|
+
- lib/envolve/error.rb
|
89
90
|
- lib/envolve/version.rb
|
90
91
|
- tasks/default.rake
|
91
92
|
- tasks/this.rb
|