en 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 +4 -4
- data/README.md +49 -0
- data/lib/en.rb +8 -4
- data/lib/en/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483651d5ac02c37ae6ea8ad520d222df5a6a529f
|
4
|
+
data.tar.gz: 8b1506b87f556a45d3f4f131dcaa4b942c998d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 212574b54996398ce89aff571b12ecbfaa951495cc7817178134e7a1f9f77bd373334de4c289f78c263d04cf5fa8aa92791187067cfe51f2bbe72dc037ff9be4
|
7
|
+
data.tar.gz: f6a323fb351ab17fb2c12f07fe9ac4aebc8e4e9da680f8638e795d7856201070ba348c1b84079abe2074952ed9389f2f51362d7aa216da2739ae447d1ba25755
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# EN
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/rodrigues/en.png?branch=master)](https://travis-ci.org/rodrigues/en)
|
4
|
+
|
5
|
+
A simple, namespaceable environment fetcher that supports optionally [dotenv](https://github.com/bkeepers/dotenv)
|
6
|
+
|
7
|
+
To get a variable value, do:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'en'
|
11
|
+
|
12
|
+
EN[:key] # looks for ENV['KEY']
|
13
|
+
EN[:foo_bar] # looks for ENV['FOO_BAR']
|
14
|
+
```
|
15
|
+
|
16
|
+
The `#fetch` method can give you more options:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'en'
|
20
|
+
|
21
|
+
EN.fetch(:key) { 'default_value' }
|
22
|
+
|
23
|
+
EN.fetch_int(:key) # fails if value is not a valid Integer
|
24
|
+
EN.fetch_float(:key) # fails if value is not a valid Float
|
25
|
+
```
|
26
|
+
|
27
|
+
To load variables from a .env file via `dotenv`, do:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# .env file
|
31
|
+
KEY: value
|
32
|
+
|
33
|
+
# ruby file
|
34
|
+
require 'en'
|
35
|
+
|
36
|
+
EN.load
|
37
|
+
|
38
|
+
EN.fetch(:key)
|
39
|
+
```
|
40
|
+
|
41
|
+
To namespace your keys by a prefix, do:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
def redis_env
|
45
|
+
EN::Namespace.new(:redis)
|
46
|
+
end
|
47
|
+
|
48
|
+
port = redis_env.fetch_int(:port)
|
49
|
+
```
|
data/lib/en.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
require 'en/version'
|
2
2
|
|
3
|
-
require 'dotenv'
|
4
|
-
|
5
|
-
Dotenv.load
|
6
|
-
|
7
3
|
module EN
|
8
4
|
extend self
|
9
5
|
|
6
|
+
def load
|
7
|
+
require 'dotenv'
|
8
|
+
Dotenv.load
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
10
12
|
def fetch(variable)
|
11
13
|
ENV[variable.to_s.upcase] || begin
|
12
14
|
yield if block_given?
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
alias_method :[], :fetch
|
19
|
+
|
16
20
|
TYPES = {
|
17
21
|
int: method(:Integer),
|
18
22
|
integer: method(:Integer),
|
data/lib/en/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: en
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Rodrigues
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- Gemfile
|
92
92
|
- LICENSE.txt
|
93
|
+
- README.md
|
93
94
|
- Rakefile
|
94
95
|
- en.gemspec
|
95
96
|
- lib/en.rb
|