env-conf 0.0.1 → 0.0.2

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: 9df5435035857289037f37777072719bbf03be22
4
- data.tar.gz: ac4f1828b1977324d88817f0cb0e66d761e16c18
3
+ metadata.gz: 5c00969bbe2528704fd3247dcf352c9daf44acd0
4
+ data.tar.gz: 588806c188226ce34693aaf2bf629687b023cdf6
5
5
  SHA512:
6
- metadata.gz: 7cfa1abae140f8a877dc8ee1ef51989b8b342a02a0269e66042b8db80cec4d6d7eef253f94c7aeb7915cc40bc2e677bde86189b2a64ce3d919a55beb9cc9a11d
7
- data.tar.gz: 7a9830f7ea6a82972cd738e62fe2f41addb0941dd2517fed19e6302be5d79f9990efed6f5bdfb3aa3240428c6d5281377a2d27f30dca7a060f3dfdedf62449d7
6
+ metadata.gz: 10c18faff50a64c766d84c56f9bdfe37d757b20c42106606683edd775efbf9381a164aaacfea7490ea64e638920780f3f2f5e6d8529987df626f3776d6147287
7
+ data.tar.gz: ce4c1e12d0b7b4134ff83df500c386417e2ec55ed099386cc3630f3c707d2917c35ee254bfa9a86ba4eaac75fea81123e5ca2a9bd6af40aa22c66ed43fd46eea
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # env-conf
2
- ## a better `Config`
3
2
 
4
3
  Provides a better way to configure the application than simply pulling
5
- strings from `ENV`.
4
+ strings from `ENV` by overriding the deprecated `Config` class.
6
5
 
7
- #### defaults
6
+ ## Features
7
+
8
+ ### defaults
8
9
 
9
10
  ```ruby
10
11
  Config[:foo]
@@ -17,14 +18,18 @@ Config['FOO']
17
18
  # => 'bar'
18
19
  ```
19
20
 
20
- #### type casts
21
+ ### type casts
21
22
 
22
23
  Returns `nil` when undefined, otherwise casts to indicated type.
23
24
 
25
+ #### int
24
26
  ```ruby
25
27
  Config.int(:max_connections)
28
+ #=> 10
26
29
  ```
27
30
 
31
+
32
+
28
33
  ## Installation
29
34
 
30
35
  Add this line to your application's Gemfile:
data/lib/env-conf.rb CHANGED
@@ -87,6 +87,11 @@ module Config
87
87
  self['RACK_ENV'] == 'test'
88
88
  end
89
89
 
90
+ # @return [Bool] True if the service is in development mode.
91
+ def self.development?
92
+ self['RACK_ENV'] == 'development'
93
+ end
94
+
90
95
  # The `APP_NAME` env var is used to identify which codebase is
91
96
  # running in librato. This usually matches the name of the repository.
92
97
  #
@@ -104,6 +109,13 @@ module Config
104
109
  env("APP_DEPLOY")
105
110
  end
106
111
 
112
+ # The `RACK_ENV` env var is used to identify the app mode
113
+ #
114
+ # @return [Symbol] The environment of the app
115
+ def self.app_env
116
+ env!("RACK_ENV").to_sym
117
+ end
118
+
107
119
  # The port to listen on for web requests.
108
120
  #
109
121
  # @return [Fixnum] The port to listen on for web requests.
@@ -2,5 +2,5 @@
2
2
  Object.send(:remove_const, :Config) if defined?(Config)
3
3
 
4
4
  module Config
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
data/test/config_test.rb CHANGED
@@ -9,20 +9,19 @@ require 'env-conf'
9
9
  module EnvironmentHelpers
10
10
  # Override an environment variable in the current test.
11
11
  def set_env(key, value)
12
- overrides[key] = ENV[key] unless overrides.has_key?(key)
12
+ @overrides[key] = ENV[key] unless @overrides.has_key?(key)
13
13
  ENV[key] = value
14
14
  end
15
15
 
16
- # Restore the environment back to its state before tests ran.
17
- def teardown
18
- overrides.each { |key, value| ENV[key] = value }
16
+ def setup
19
17
  super
18
+ @overrides = {}
20
19
  end
21
20
 
22
- private
23
- # The overridden environment variables to restore when the test finishes.
24
- def overrides
25
- @overrides ||= {}
21
+ # Restore the environment back to its state before tests ran.
22
+ def teardown
23
+ @overrides.each { |key, value| ENV[key] = value }
24
+ super
26
25
  end
27
26
  end
28
27
 
@@ -83,6 +82,14 @@ class ConfigTest < Minitest::Test
83
82
  assert Config.production?
84
83
  end
85
84
 
85
+ # Config.development? is true when RACK_ENV=production.
86
+ def test_development_mode
87
+ set_env 'RACK_ENV', nil
88
+ refute Config.development?
89
+ set_env 'RACK_ENV', 'development'
90
+ assert Config.development?
91
+ end
92
+
86
93
  # Config.test? is true when RACK_ENV=test.
87
94
  def test_test_mode
88
95
  set_env 'RACK_ENV', nil
@@ -213,4 +220,17 @@ class ConfigTest < Minitest::Test
213
220
  Config.default(:foo, false)
214
221
  assert_equal(false, Config.bool?(:foo))
215
222
  end
223
+
224
+ def test_app_env
225
+ set_env 'RACK_ENV', nil
226
+ assert_raises RuntimeError do
227
+ Config.app_env
228
+ end
229
+ set_env 'RACK_ENV', 'test'
230
+ assert_equal(:test, Config.app_env)
231
+ set_env 'RACK_ENV', 'development'
232
+ assert_equal(:development, Config.app_env)
233
+ set_env 'RACK_ENV', 'production'
234
+ assert_equal(:production, Config.app_env)
235
+ end
216
236
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Continanza