service_config 0.0.2 → 0.1.0
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/.rspec +2 -0
- data/README.md +7 -0
- data/Rakefile +6 -1
- data/lib/service_config/provider.rb +8 -6
- data/lib/service_config/version.rb +1 -1
- data/service_config.gemspec +4 -4
- data/spec/provider_spec.rb +11 -1
- metadata +23 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f51c3106a49aafd46a8cead89feb0b5c8d38fa98
|
4
|
+
data.tar.gz: 912693d1404f997479d029d9d90d799c5b7c1248
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48faa8b520269c1f5cad8c34c4a8fb17a841aea9ffb6a4cec3bf86ac7d57252ad328e7a5da1e7a4b84894e41cc91638b6f497b2608cfc36172628d1832ccc3c7
|
7
|
+
data.tar.gz: 77a1966010419f922c0b097f14f9aecc6609ebaac549670c24804049d55f4510316e316403eb4b6ccafc4ffefdbcdbc02e9b9a2f17af9f362c8f81a296a69fd5
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# ServiceConfig
|
2
|
+

|
2
3
|
|
3
4
|
Use this gem to expose environment variables to your code, with clear
|
4
5
|
defaults and error handling for when the environment variables are
|
@@ -25,6 +26,12 @@ And then execute:
|
|
25
26
|
|
26
27
|
provider.internal_server # => 'http://localhost:3000/'
|
27
28
|
provider.soundcloud_server # => 'http://api.soundcloud.com/'
|
29
|
+
|
30
|
+
Configure mandatory options individually
|
31
|
+
|
32
|
+
ServiceConfig::Provider.new(:raise_if_nil => false) do |config|
|
33
|
+
config.provides :some_key, 'default', :raise_if_nil => true
|
34
|
+
end
|
28
35
|
|
29
36
|
## Contributing
|
30
37
|
|
data/Rakefile
CHANGED
@@ -6,8 +6,8 @@ module ServiceConfig
|
|
6
6
|
yield self
|
7
7
|
end
|
8
8
|
|
9
|
-
def provides(name, default_value = '')
|
10
|
-
|
9
|
+
def provides(name, default_value = '', options = {})
|
10
|
+
raise_unset(name) if guarded_against_unset?(name, options)
|
11
11
|
|
12
12
|
self.class.send(:define_method, name) do
|
13
13
|
lookup_value(name) || default_value
|
@@ -16,12 +16,14 @@ module ServiceConfig
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
19
|
+
def raise_unset(name)
|
20
20
|
env_variable_name = name.to_s.upcase
|
21
|
+
raise "must set #{env_variable_name}" unless ENV[env_variable_name]
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def guarded_against_unset?(name, options)
|
25
|
+
return options[:raise_if_nil] if options.has_key?(:raise_if_nil)
|
26
|
+
@raise_if_nil
|
25
27
|
end
|
26
28
|
|
27
29
|
def lookup_value(name)
|
data/service_config.gemspec
CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'service_config/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'service_config'
|
8
8
|
gem.version = ServiceConfig::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
9
|
+
gem.authors = ['Karl Eklund', 'Mikael Amborn', 'Mike Burns', 'Lennart Fridén']
|
10
|
+
gem.email = ['info@magplus.com']
|
11
11
|
gem.description = %q{Configure your values using the environment, with fallbacks}
|
12
12
|
gem.summary = %q{Configure your values using the environment, with fallbacks}
|
13
13
|
gem.homepage = ""
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
21
|
gem.add_development_dependency 'rake'
|
data/spec/provider_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe ServiceConfig::Provider do
|
|
12
12
|
service_config.foo.should == 'yo'
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'raises if an environment variable is not set, if configured' do
|
15
|
+
it 'raises if an environment variable is not set, if configured globally' do
|
16
16
|
expect {
|
17
17
|
build_service_config(:raise_if_nil => true) { |c| c.provides :unset }
|
18
18
|
}.to raise_error('must set UNSET')
|
@@ -22,6 +22,16 @@ describe ServiceConfig::Provider do
|
|
22
22
|
}.not_to raise_error
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'raises if an environment variable is not set, if configured on specific variable' do
|
26
|
+
expect {
|
27
|
+
build_service_config(:raise_if_nil => false) { |c| c.provides :unset, nil, :raise_if_nil => true }
|
28
|
+
}.to raise_error('must set UNSET')
|
29
|
+
|
30
|
+
expect {
|
31
|
+
build_service_config(:raise_if_nil => true) { |c| c.provides :unset, nil, :raise_if_nil => false }
|
32
|
+
}.to_not raise_error
|
33
|
+
end
|
34
|
+
|
25
35
|
it 'defines the value as "" if the environment variable is unset' do
|
26
36
|
service_config = build_service_config(:raise_if_nil => false, :use_env => true) { |c| c.provides :unknown }
|
27
37
|
service_config.unknown.should == ''
|
metadata
CHANGED
@@ -1,40 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Karl Eklund
|
9
8
|
- Mikael Amborn
|
10
9
|
- Mike Burns
|
10
|
+
- Lennart Fridén
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
18
|
-
requirement:
|
19
|
-
none: false
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
20
19
|
requirements:
|
21
|
-
- -
|
20
|
+
- - '>='
|
22
21
|
- !ruby/object:Gem::Version
|
23
22
|
version: '0'
|
24
23
|
type: :development
|
25
24
|
prerelease: false
|
26
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
|
-
requirement:
|
30
|
-
none: false
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
31
33
|
requirements:
|
32
|
-
- -
|
34
|
+
- - '>='
|
33
35
|
- !ruby/object:Gem::Version
|
34
36
|
version: '0'
|
35
37
|
type: :development
|
36
38
|
prerelease: false
|
37
|
-
version_requirements:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
38
44
|
description: Configure your values using the environment, with fallbacks
|
39
45
|
email:
|
40
46
|
- info@magplus.com
|
@@ -43,6 +49,7 @@ extensions: []
|
|
43
49
|
extra_rdoc_files: []
|
44
50
|
files:
|
45
51
|
- .gitignore
|
52
|
+
- .rspec
|
46
53
|
- Gemfile
|
47
54
|
- LICENSE.txt
|
48
55
|
- README.md
|
@@ -54,33 +61,26 @@ files:
|
|
54
61
|
- spec/provider_spec.rb
|
55
62
|
homepage: ''
|
56
63
|
licenses: []
|
64
|
+
metadata: {}
|
57
65
|
post_install_message:
|
58
66
|
rdoc_options: []
|
59
67
|
require_paths:
|
60
68
|
- lib
|
61
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
70
|
requirements:
|
64
|
-
- -
|
71
|
+
- - '>='
|
65
72
|
- !ruby/object:Gem::Version
|
66
73
|
version: '0'
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
hash: 4394547025718333306
|
70
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
75
|
requirements:
|
73
|
-
- -
|
76
|
+
- - '>='
|
74
77
|
- !ruby/object:Gem::Version
|
75
78
|
version: '0'
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
hash: 4394547025718333306
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.14
|
82
82
|
signing_key:
|
83
|
-
specification_version:
|
83
|
+
specification_version: 4
|
84
84
|
summary: Configure your values using the environment, with fallbacks
|
85
85
|
test_files:
|
86
86
|
- spec/provider_spec.rb
|