service_config 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # ServiceConfig
2
+ ![Gem version](https://badge.fury.io/rb/service_config.png)
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
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -6,8 +6,8 @@ module ServiceConfig
6
6
  yield self
7
7
  end
8
8
 
9
- def provides(name, default_value = '')
10
- guard_against_unset_env(name) if @raise_if_nil
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 guard_against_unset_env(name)
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
- unless ENV[env_variable_name]
23
- raise "must set #{env_variable_name}"
24
- end
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)
@@ -1,3 +1,3 @@
1
1
  module ServiceConfig
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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 = "service_config"
7
+ gem.name = 'service_config'
8
8
  gem.version = ServiceConfig::VERSION
9
- gem.authors = ["Karl Eklund", "Mikael Amborn", "Mike Burns"]
10
- gem.email = ["info@magplus.com"]
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 = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'rake'
@@ -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.2
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: 2013-01-23 00:00:00.000000000 Z
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: &70335603313740 !ruby/object:Gem::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: *70335603313740
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: &70335603313320 !ruby/object:Gem::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: *70335603313320
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: 1.8.10
81
+ rubygems_version: 2.0.14
82
82
  signing_key:
83
- specification_version: 3
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