fastenv 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +18 -0
- data/lib/fastenv.rb +3 -0
- data/lib/fastenv/version.rb +1 -1
- data/spec/fastenv_spec.rb +33 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5466eea63c2c059d113aadc176cc10ce7648b6ce
|
4
|
+
data.tar.gz: 60d068ed8bafaad16af746510b66d7233566ba68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd1295c108c6cf8b92aa28e20ad72e4bec55006b974946fbd8a0d0d98dce8247d6904d41e4a01bc32dc2538fe133037ef7c3311a7cf07be47a76c694b1f15bf
|
7
|
+
data.tar.gz: 26259bcbf842d494bdf5f67f5ab7593eb6c957e4d009a38edd212bf65a36865e262895d6dd726c2c358670c1c383f684b39e99c8cd921b7823b66f1061f03fb5
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Fastenv
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/fastenv.svg)](http://badge.fury.io/rb/fastenv)
|
4
|
+
[![Build Status](https://travis-ci.org/kyletolle/fastenv.svg?branch=master)](https://travis-ci.org/kyletolle/fastenv)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/kyletolle/fastenv/badges/gpa.svg)](https://codeclimate.com/github/kyletolle/fastenv)
|
6
|
+
[![Dependency Status](https://gemnasium.com/kyletolle/fastenv.svg)](https://gemnasium.com/kyletolle/fastenv)
|
7
|
+
|
3
8
|
Fast access to environment variables. Takes advantage of method_missing to
|
4
9
|
easily return values of environment variable.
|
5
10
|
|
@@ -46,6 +51,19 @@ If the environment variable doesn't exist, a `NameError` will be raise.
|
|
46
51
|
Fastenv is intended for querying credentials. Missing credentials is an
|
47
52
|
exceptional event.
|
48
53
|
|
54
|
+
### Defaults
|
55
|
+
|
56
|
+
It can be helpful to specify default values though. You can give Fastenv a
|
57
|
+
block, and, if the environment variable is not set, the block will be evaluated
|
58
|
+
and its value returned.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'fastenv'
|
62
|
+
|
63
|
+
your_special_value = Fastenv.env_does_not_exist { 'but this is a default' }
|
64
|
+
=> "but this is a default"
|
65
|
+
```
|
66
|
+
|
49
67
|
---
|
50
68
|
|
51
69
|
## Goes Well With
|
data/lib/fastenv.rb
CHANGED
data/lib/fastenv/version.rb
CHANGED
data/spec/fastenv_spec.rb
CHANGED
@@ -5,32 +5,55 @@ describe Fastenv do
|
|
5
5
|
expect(Fastenv::VERSION).not_to be nil
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
context 'when asked about an existing environment variable' do
|
9
9
|
let(:expected_env_var_value) { '/this/path/may/or/may/not/exist' }
|
10
10
|
|
11
11
|
before do
|
12
|
-
ENV[
|
12
|
+
ENV['THIS_ENV_VAR_IS_SET'] = expected_env_var_value
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
context 'with a block given' do
|
16
|
+
it 'returns the value of the environment variable' do
|
17
|
+
expect(Fastenv.this_env_var_is_set { 'mordor' })
|
18
|
+
.to eq expected_env_var_value
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with no block given' do
|
24
|
+
it 'returns the value of the environment variable' do
|
25
|
+
expect(Fastenv.this_env_var_is_set).to eq expected_env_var_value
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
19
29
|
|
20
|
-
|
30
|
+
context 'when asked about a non-existent environment variable' do
|
21
31
|
let(:unset_env_var) { 'THIS_ENV_VAR_DOES_NOT_EXIST' }
|
22
32
|
|
23
33
|
before do
|
24
34
|
ENV[unset_env_var] = nil
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
37
|
+
context 'with a block given' do
|
38
|
+
let(:default_value) do
|
39
|
+
'but there is a default'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns the value from the block' do
|
43
|
+
expect(Fastenv.this_env_var_does_not_exist { default_value })
|
44
|
+
.to eq(default_value)
|
45
|
+
end
|
29
46
|
end
|
30
47
|
|
31
|
-
|
32
|
-
|
33
|
-
.to raise_error
|
48
|
+
context 'with no block given' do
|
49
|
+
it 'raises an argument error' do
|
50
|
+
expect{Fastenv.this_env_var_does_not_exist}.to raise_error(NameError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'gives a good error message' do
|
54
|
+
expect{Fastenv.this_env_var_does_not_exist}
|
55
|
+
.to raise_error.with_message(/Couldn't find .* #{unset_env_var}/)
|
56
|
+
end
|
34
57
|
end
|
35
58
|
end
|
36
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Tolle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
65
|
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|
@@ -92,11 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.5.1
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Fast access to environment variables.
|
99
100
|
test_files:
|
100
101
|
- spec/fastenv_spec.rb
|
101
102
|
- spec/spec_helper.rb
|
102
|
-
has_rdoc:
|