env.rb 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +40 -18
- data/lib/env/version.rb +1 -1
- data/lib/env.rb +4 -1
- data/spec/import_spec.rb +1 -1
- data/spec/load_spec.rb +19 -0
- data/spec/uri_spec.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -20,9 +20,30 @@ your Envfile to a shell-compatible format, and executing scripts within your env
|
|
20
20
|
|
21
21
|
## Examples
|
22
22
|
|
23
|
-
###
|
23
|
+
### Explictly declaring your environment
|
24
24
|
|
25
|
-
|
25
|
+
#### Envfile
|
26
|
+
import 'TEST'
|
27
|
+
export 'TEXT', '15'
|
28
|
+
|
29
|
+
#### Use
|
30
|
+
|
31
|
+
require 'env'
|
32
|
+
|
33
|
+
ENV['HELLO_WORLD'] # => nil
|
34
|
+
ENV['TEST'] = 5
|
35
|
+
Env.load! # look for Envfile
|
36
|
+
|
37
|
+
ENV['HELLO_WORLD']
|
38
|
+
# => EnvironmentError: HELLO_WORLD is not a declared dependency
|
39
|
+
|
40
|
+
ENV['TEST'] # => 5
|
41
|
+
ENV['TEXT'] # => 15
|
42
|
+
|
43
|
+
### Groups
|
44
|
+
#### Envfile
|
45
|
+
|
46
|
+
export "PROVIDER_PASSWORD", '1234', :group => :development
|
26
47
|
|
27
48
|
group :development do
|
28
49
|
export "SERVICE_URL", 'http://username:password@www.service.com/path"
|
@@ -32,35 +53,36 @@ your Envfile to a shell-compatible format, and executing scripts within your env
|
|
32
53
|
export "SERVICE_URL", 'http://username:password@example.com/"
|
33
54
|
end
|
34
55
|
|
35
|
-
|
56
|
+
#### Use
|
57
|
+
Env.load!
|
58
|
+
-same as-
|
59
|
+
Env.load! :default
|
36
60
|
|
37
|
-
|
61
|
+
Env.load! :default, :test
|
62
|
+
ENV['SERVICE_URL'] # => 'http://username:password@example.com/"
|
38
63
|
|
39
|
-
Env.load
|
40
|
-
|
64
|
+
Env.load! :development
|
65
|
+
ENV['SERVICE_URL'] # => 'http://username:password@www.service.com/path"
|
41
66
|
|
42
|
-
|
43
|
-
Env.enforce
|
44
|
-
ENV['HELLO_WORLD']
|
45
|
-
# => EnvironmentError: HELLO_WORLD is not a declared dependency
|
67
|
+
### Mutability
|
46
68
|
|
47
|
-
|
48
|
-
|
69
|
+
#### Envfile
|
70
|
+
export 'TEXT', '15', :mutable => false
|
71
|
+
export 'TEXT', '15', :immutable => false
|
49
72
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
73
|
+
#### Use
|
74
|
+
|
75
|
+
ENV['TEST'] # => 15
|
54
76
|
|
55
77
|
ENV['TEST'] = 'overriding'
|
56
78
|
# => EnvironmentError: variable TEST cannot be changed
|
57
79
|
|
58
80
|
## Built-in support for URIs
|
59
81
|
|
60
|
-
###
|
82
|
+
### Envfile
|
61
83
|
export "SERVICE", 'http://username:password@example.com/"
|
62
84
|
|
63
|
-
###
|
85
|
+
### Use
|
64
86
|
ENV['SERVICE'] #=> 'http://username:password@example.com/"
|
65
87
|
ENV['SERVICE'].base_uri #=> 'http://example.com/"
|
66
88
|
ENV['SERVICE'].url #=> 'http://example.com/"
|
data/lib/env/version.rb
CHANGED
data/lib/env.rb
CHANGED
@@ -17,6 +17,7 @@ module Env
|
|
17
17
|
@@enforced = false
|
18
18
|
@@groups = Hash.new { |hash, key| hash[key] = [] }
|
19
19
|
@@default_group = :default
|
20
|
+
@@callback = nil
|
20
21
|
end
|
21
22
|
|
22
23
|
def [](key)
|
@@ -63,7 +64,8 @@ module Env
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
def load!(*groups)
|
67
|
+
def load!(*groups, &block)
|
68
|
+
@@callback = block if block_given?
|
67
69
|
@@enforced or Env.enforce
|
68
70
|
eval File.read("Envfile") if File.exist?("Envfile")
|
69
71
|
groups = [:default] if groups.empty?
|
@@ -102,6 +104,7 @@ module Env
|
|
102
104
|
|
103
105
|
private
|
104
106
|
def _raise(key)
|
107
|
+
return @@callback.call(key) if @@callback
|
105
108
|
raise EnvironmentError, "#{key} is not a declared dependency, add it to your Envfile"
|
106
109
|
end
|
107
110
|
|
data/spec/import_spec.rb
CHANGED
data/spec/load_spec.rb
CHANGED
@@ -28,4 +28,23 @@ describe Env, '::load!' do
|
|
28
28
|
ENV['FOO'].should == 'bar'
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
context "when passed a block" do
|
33
|
+
before do
|
34
|
+
envfile("")
|
35
|
+
@name = nil
|
36
|
+
Env.load! { |name| @name = name }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not raise and error by default" do
|
40
|
+
lambda { ENV['FOO'] }.should_not raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should pass the undeclared depencdies's key to the block" do
|
44
|
+
ENV['FOO']
|
45
|
+
@name.should == 'FOO'
|
46
|
+
ENV['bar']
|
47
|
+
@name.should == 'bar'
|
48
|
+
end
|
49
|
+
end
|
31
50
|
end
|
data/spec/uri_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: env.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-19 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: Allows your to manage many ENV vars by declaring them as dependencies
|