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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89d95332b8d91bbba1eb1523620932eb276e641f
4
- data.tar.gz: 8517cf01810d392a8384754023b3bd3de5c330ee
3
+ metadata.gz: 5466eea63c2c059d113aadc176cc10ce7648b6ce
4
+ data.tar.gz: 60d068ed8bafaad16af746510b66d7233566ba68
5
5
  SHA512:
6
- metadata.gz: a1208a38f61a7a81bfef27150593da1a5f31fb2aa8a8845aa585273c1df711444550e9016a04297c96cc047a7ed14df11822c7c922edb225a50c5902a40c772e
7
- data.tar.gz: 97c0d65a617a616389ceaaed40732d856534cc1965911f69ec92c2c4042fd0bfd2d2156e00b1048bcf00087f6593ed2106bfb1c245927f1ead1485228233eb59
6
+ metadata.gz: 4fd1295c108c6cf8b92aa28e20ad72e4bec55006b974946fbd8a0d0d98dce8247d6904d41e4a01bc32dc2538fe133037ef7c3311a7cf07be47a76c694b1f15bf
7
+ data.tar.gz: 26259bcbf842d494bdf5f67f5ab7593eb6c957e4d009a38edd212bf65a36865e262895d6dd726c2c358670c1c383f684b39e99c8cd921b7823b66f1061f03fb5
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.0.3
4
+
5
+ - Allow blocks to be passed for use as default values
6
+
7
+ ## 0.0.2
8
+
9
+ - Update homepage in gemspec
10
+ - Add details to README
11
+
12
+ ## 0.0.1
13
+
14
+ - Initial release
15
+
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
@@ -7,6 +7,9 @@ class Fastenv
7
7
  if ENV.include?(env_var)
8
8
  ENV[env_var]
9
9
 
10
+ elsif block_given?
11
+ yield
12
+
10
13
  else
11
14
  raise NameError, "Couldn't find the environment variable named #{env_var}"
12
15
  end
@@ -1,4 +1,4 @@
1
1
  class Fastenv
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
4
4
 
@@ -5,32 +5,55 @@ describe Fastenv do
5
5
  expect(Fastenv::VERSION).not_to be nil
6
6
  end
7
7
 
8
- describe "when asked about an existing environment variable" do
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["THIS_ENV_VAR_IS_SET"] = expected_env_var_value
12
+ ENV['THIS_ENV_VAR_IS_SET'] = expected_env_var_value
13
13
  end
14
14
 
15
- it "returns the value of the environment variable" do
16
- expect(Fastenv.this_env_var_is_set).to eq expected_env_var_value
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
- describe "when asked about a non-existent environment variable" do
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
- it "raises an argument error" do
28
- expect{Fastenv.this_env_var_does_not_exist}.to raise_error(NameError)
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
- it "gives a good error message" do
32
- expect{Fastenv.this_env_var_does_not_exist}
33
- .to raise_error.with_message(/Couldn't find .* #{unset_env_var}/)
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.2
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: 2015-04-08 00:00:00.000000000 Z
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.4.5
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: