dot_env 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -1
- data/lib/dot_env.rb +0 -6
- data/lib/dot_env/parser.rb +3 -1
- data/lib/dot_env/version.rb +1 -1
- data/spec/dot_env_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7443ad9f09e454c484d03a691f8fddbc5dcc82b1
|
4
|
+
data.tar.gz: c64a46f7cd37bad12f3fece9697688740c02f524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 796b54c21373af9fe89bfbaaaf598e2ddc48b836d5823efffa82fc0d3c7f1588385e5ba3be8a7ffc2b32b792f6ce775f0119333058311f0ce73f7be87c11ab96
|
7
|
+
data.tar.gz: 72c3ae51c10893e83b4f5611e6c2008aaa72d784294d9e07f7837eeb86d6dbc112175f4f64747ccdf9d6e1e37066e6dc170d091c21f6ad9622023f8b8ce17d96
|
data/README.md
CHANGED
@@ -6,12 +6,16 @@
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'dot_env'
|
9
|
+
gem 'dot_env'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
13
13
|
$ bundle
|
14
14
|
|
15
|
+
Or simply:
|
16
|
+
|
17
|
+
$ gem install dot_env
|
18
|
+
|
15
19
|
## Usage
|
16
20
|
|
17
21
|
Basic usage:
|
@@ -38,6 +42,21 @@ You can use any other name for your settings file, and you can add that name as
|
|
38
42
|
|
39
43
|
After parsing every variable's type will be `string`, except booleans and arrays.
|
40
44
|
|
45
|
+
Environment settings file example:
|
46
|
+
|
47
|
+
# example .env file
|
48
|
+
|
49
|
+
APP_ENV = "development"
|
50
|
+
APP_ROOT = $PWD
|
51
|
+
AN_ARRAY = ['one', '$HOME', True, 42]
|
52
|
+
|
53
|
+
There could be empty, and comment rows (prepended with a `#` sign at the beginning of the row) in the file.
|
54
|
+
|
55
|
+
After setting up the environment, you could access these variables from your code:
|
56
|
+
|
57
|
+
ENV['APP_ENV'] #=> 'development'
|
58
|
+
ENV['APP_ROOT'] #=> '/path/to/here'
|
59
|
+
ENV['AN_ARRAY'] #=> ['one', '/home/username', true, '42']
|
41
60
|
|
42
61
|
## Contributing
|
43
62
|
|
data/lib/dot_env.rb
CHANGED
@@ -4,8 +4,6 @@ require_relative 'dot_env/parser'
|
|
4
4
|
require_relative 'dot_env/environment'
|
5
5
|
|
6
6
|
module DotEnv
|
7
|
-
@log = Logger.new($stdout)
|
8
|
-
@log.level = Logger::DEBUG
|
9
7
|
@parser = DotEnv::Parser
|
10
8
|
@env = DotEnv::Environment.new(@parser, ARGV)
|
11
9
|
@env_file = @env.fetch('ENVIRONMENT_SETTINGS_FILE', '.env')
|
@@ -21,16 +19,12 @@ module DotEnv
|
|
21
19
|
|
22
20
|
def self.set_default_env(filepath)
|
23
21
|
current_env = @env.get_current
|
24
|
-
# @log.info "Environment settings file ('#{filepath}') not found."
|
25
|
-
# @log.info "Setting up #{current_env} environment."
|
26
22
|
@env.set_current(current_env)
|
27
23
|
end
|
28
24
|
|
29
25
|
def self.set_environment(filepath)
|
30
26
|
self.read_env_file(filepath)
|
31
27
|
current_env = @env.get_current
|
32
|
-
# @log.info "Environment settings file ('#{filepath}') found."
|
33
|
-
# @log.info "Setting up #{current_env} environment."
|
34
28
|
rescue Errno::ENOENT
|
35
29
|
self.set_default_env(filepath)
|
36
30
|
end
|
data/lib/dot_env/parser.rb
CHANGED
@@ -4,7 +4,9 @@ module DotEnv
|
|
4
4
|
FALSEWORDS = ['false', 'no', '0']
|
5
5
|
|
6
6
|
def self.get_value_pair(line)
|
7
|
-
|
7
|
+
key, value = line.chomp.split('=').each {|v| v.gsub!(/['"]/, '') }.each(&:strip!)
|
8
|
+
value = self.expand(value)
|
9
|
+
[key, value]
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.cleanup(value)
|
data/lib/dot_env/version.rb
CHANGED
data/spec/dot_env_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe DotEnv do
|
|
17
17
|
ENV['APP_NAME'].must_equal 'testapp'
|
18
18
|
ENV['AN_ARRAY'].must_equal '[egy, ketto, harom]'
|
19
19
|
ENV['UNBELIEVABLE'].must_equal 'True'
|
20
|
-
ENV['SOMEWHERE'].must_equal '
|
20
|
+
ENV['SOMEWHERE'].must_equal ENV['HOME']
|
21
21
|
end
|
22
22
|
|
23
23
|
it "can read back those settings" do
|