configuration_service 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d77ac4451fbc4e6b19276dddbba08a4d44240cb
4
- data.tar.gz: d645e3e4b48494e7f8bbd84b73a194c45f257a0c
3
+ metadata.gz: a8a12bd4bf52fe773fde0b4306ba47c9d9f33d90
4
+ data.tar.gz: 64b84d7cf9c08401d56c0c8f4b7c9d9ac40c59c6
5
5
  SHA512:
6
- metadata.gz: b3dbe5db6da2659032e7d15fb55ed98173e8cc7ff6cffa7af6610c64aa4f49dfa4949826b4984d1b1adb4598bf8dd9c76b6149c4aab8e0f34bb2311f88476e16
7
- data.tar.gz: 8c89bd07e788933c053b369fd642ee8768d7faa9d42726afcaf2c779af8ab6f134d0815a81bda1f9057be8221861ed281761cef8423be2ebf51568097bea8dd1
6
+ metadata.gz: 374a86490e8e6d0c42d3c13058a60320f016efae154ba4d370ccf30547ea72df3ebd0cb347aa8f38c8602467c3f4f08f537f601fe8b99902e6fead53d387fe7b
7
+ data.tar.gz: beb9ea330992004c10fbb7782d808799c48534b9c79681ddb2abdcfce0697f9a30dc1c5c1af0ca30bc8e3d6d58f65d398ed7a1510c1114b9c6d462a146ad5b96
data/.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rake", "~> 11.1"
23
23
  spec.add_development_dependency "cucumber", "~> 2.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.3"
25
25
  spec.add_development_dependency "rspec-expectations", "~> 3.3"
@@ -6,8 +6,9 @@ module ConfigurationService
6
6
 
7
7
  class EnvDict < Hash
8
8
 
9
- def initialize(env, *path)
10
- @env = env
9
+ def initialize(sources, *path)
10
+ @sources = sources.is_a?(Array) ? sources : [ sources ]
11
+ @env = @sources.inject { |m, e| m.merge(e) }
11
12
  @path = build_path(*path)
12
13
 
13
14
  env_keys.each do |k|
@@ -58,8 +59,8 @@ module ConfigurationService
58
59
  raise KeyError, "missing environment variable #{envar}"
59
60
  end
60
61
 
61
- def env_keys
62
- @env.keys.select { |k| under_path?(k) }
62
+ def env_keys(env = @env)
63
+ env.keys.select { |k| under_path?(k) }
63
64
  end
64
65
 
65
66
  def under_path?(k)
@@ -96,8 +97,8 @@ module ConfigurationService
96
97
  end
97
98
 
98
99
  def scrub_env!
99
- env_keys.each do |k|
100
- @env.delete(k)
100
+ @sources.each do |env|
101
+ env_keys(env).each { |k| env.delete(k) }
101
102
  end
102
103
  end
103
104
 
@@ -46,8 +46,8 @@ module ConfigurationService
46
46
  ##
47
47
  # Returns a new factory
48
48
  #
49
- # @param [Hash] env
50
- # the string-keyed environment
49
+ # @param [Hash, Array<Hash>] sources
50
+ # one or a list of the string-keyed environments
51
51
  # @param [String] prefix
52
52
  # the prefix for matching environment variable names
53
53
  #
@@ -55,8 +55,8 @@ module ConfigurationService
55
55
  # they can use {.create} which instantiates a factory with default +env+ and +prefix+
56
56
  # and uses that internally.
57
57
  #
58
- def initialize(env = ENV, prefix = DEFAULT_PREFIX)
59
- @env = EnvDict.new(env, prefix)
58
+ def initialize(sources = default_sources, prefix = DEFAULT_PREFIX)
59
+ @env = EnvDict.new(sources, prefix)
60
60
  end
61
61
 
62
62
  ##
@@ -73,6 +73,9 @@ module ConfigurationService
73
73
  # [PROVIDER_*] configuration options for the service provider
74
74
  # (see service provider documentation)
75
75
  #
76
+ # On JRuby, system properties are also scanned. Where a system property and environment variable of the
77
+ # same name exist, the environment variable is preferred.
78
+ #
76
79
  # The service provider class is fetched from the {ConfigurationService::ProviderRegistry} using +PROVIDER+.
77
80
  # A service provider instance is then constructed with a dictionary of the +PROVIDER_*+ variables,
78
81
  # in which the keys are the name of the variable without +PROVIDER_+, downcased and intern'd.
@@ -80,7 +83,8 @@ module ConfigurationService
80
83
  # Then a service {ConfigurationService::Base} is constructed with the +IDENTIFIER+, +TOKEN+ and service provider instance.
81
84
  #
82
85
  # And finally, the environment is scrubbed of the variables used, to protect them from accidental exposure
83
- # (e.g. in an exception handler that prints the environment).
86
+ # (e.g. in an exception handler that prints the environment). On JRuby, system properties are scrubbed of variables used as well,
87
+ # regardless of whether they were overridden by environment variables.
84
88
  #
85
89
  # @return [ConfigurationService::Base] the configuration service instance created
86
90
  # @raise [ProviderNotFoundError] if no service provider has been registered with the name given by +PROVIDER+
@@ -104,6 +108,10 @@ module ConfigurationService
104
108
 
105
109
  private
106
110
 
111
+ def default_sources
112
+ (RUBY_PLATFORM == "java" ? [java.lang.System.properties, ENV] : ENV)
113
+ end
114
+
107
115
  def provider
108
116
  provider_id = @env[:provider]
109
117
  provider_config = @env.subslice(:provider)
@@ -1,5 +1,5 @@
1
1
  module ConfigurationService
2
2
 
3
- VERSION = "2.0.6"
3
+ VERSION = "2.1.0"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configuration_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '11.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '11.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cucumber
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.4.8
147
+ rubygems_version: 2.5.1
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: Configuration service