require_env 1.1.0 → 1.2.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: 8eb9728be43545f46faf31271e028c8fed316091
4
- data.tar.gz: fb02df77efae3aef38a1e758fcf4afd2dc94b027
3
+ metadata.gz: d33a771e94b3d7d8c419e3a0e1c4158f43e54c4b
4
+ data.tar.gz: 617169569bb0aa0b01680df6cd80993c6c6857a9
5
5
  SHA512:
6
- metadata.gz: 9e4cd887a4627c2b6aa4abfcc6d21757d5b0fa7430c169f465f0d2ed36d742b9c69b99b00d10c0283dd0b3f4cba94527f693bc38b496767e9a944163b511c273
7
- data.tar.gz: 4f8a49ab4c57d2bb12dc1c2d2e3868f19902e3d4798456f11ca485dd1b8ecff3c8490c7d175c6ab8a0163ed5a7de3f40a2ec6d5aaaa43c3481c1ceec37e8fd7e
6
+ metadata.gz: 5b3504e430afae5c725a742800cf8eeec319056ce41e64e4548f0b791e7be7fbeed90b7b2cd0be0cc1cd2ca3f90eb6054a5609fd283665f01f998055d0ee1032
7
+ data.tar.gz: 58f0ef96ab00a6269b85c5dc8480072e6a1c93e97a550c535c5587e3137c1e34a62fb0196cb626b94d559d4459a572cbefddc5601e69eb54cfa51e349de2d241
@@ -5,11 +5,12 @@ require 'erb'
5
5
  module RequireEnv
6
6
  def self.check(*files)
7
7
  check_multiple_requirements(files.map do |file|
8
- requirements = requirements_from_file(file)[application_environment]
9
- if requirements.nil?
8
+ requirements = requirements_from_file(file)
9
+ env_requirements = requirements[application_environment] || requirements[fallback_environment]
10
+ if env_requirements.nil?
10
11
  raise ArgumentError.new("#{file} does not define anything for environment: #{application_environment}")
11
12
  end
12
- [file, requirements]
13
+ [file, env_requirements]
13
14
  end)
14
15
  end
15
16
 
@@ -58,4 +59,11 @@ module RequireEnv
58
59
  def self.application_environment=(value)
59
60
  @application_environment = value
60
61
  end
62
+
63
+ def self.fallback_environment
64
+ @fallback_environment ||= nil
65
+ end
66
+ def self.fallback_environment=(value)
67
+ @fallback_environment = value
68
+ end
61
69
  end
@@ -1,3 +1,3 @@
1
1
  module RequireEnv
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -10,6 +10,10 @@ class RequireEnvTest < ActiveSupport::TestCase
10
10
  ENV.delete('BAZ')
11
11
  end
12
12
 
13
+ teardown do
14
+ RequireEnv.fallback_environment = nil
15
+ end
16
+
13
17
  test 'truth' do
14
18
  assert_kind_of Module, RequireEnv
15
19
  end
@@ -42,6 +46,21 @@ class RequireEnvTest < ActiveSupport::TestCase
42
46
  assert_equal 'whatever', RequireEnv.application_environment
43
47
  end
44
48
 
49
+ test 'fallback_environment' do
50
+ file = File.expand_path('../test.yml', __FILE__)
51
+ ENV['FOO'] = 'bar'
52
+ RequireEnv.application_environment = 'check'
53
+
54
+ assert_raise(ArgumentError) do
55
+ RequireEnv.check(file, file)
56
+ end
57
+
58
+ RequireEnv.fallback_environment = 'test'
59
+ assert_nothing_raised do
60
+ RequireEnv.check(file, file)
61
+ end
62
+ end
63
+
45
64
  test 'requirements_from_file' do
46
65
  assert_raise(ArgumentError) do
47
66
  RequireEnv.requirements_from_file('foobar')
@@ -53,7 +72,7 @@ class RequireEnvTest < ActiveSupport::TestCase
53
72
  assert_kind_of Hash, result
54
73
  assert_equal 'foo', result.dig('test', 'VAR')
55
74
  assert_equal 2, result.dig('test', 'SUM')
56
- assert_equal nil, result.dig('test', 'FOO')
75
+ assert_nil result.dig('test', 'FOO')
57
76
  end
58
77
 
59
78
  test 'check_requirements' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: require_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Planquart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
@@ -65,6 +65,7 @@ signing_key:
65
65
  specification_version: 4
66
66
  summary: Simple environment variable check
67
67
  test_files:
68
- - test/require_env_test.rb
69
- - test/test.yml
70
68
  - test/test_helper.rb
69
+ - test/test.yml
70
+ - test/require_env_test.rb
71
+ has_rdoc: