env.rb 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ testapp
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ### Note: I am practicing Readme Driven Development here so don't expect all features to work until 1.0
2
+
1
3
  # Env.rb
2
4
  Managing your ENVironment
3
5
 
@@ -40,13 +42,13 @@ your Envfile to a shell-compatible format, and executing scripts within your env
40
42
  ENV['HELLO_WORLD'] # => nil
41
43
  Env.enforce
42
44
  ENV['HELLO_WORLD']
43
- # => EnvironmentError: HELLO_WORLD is not a declared environment dependency
45
+ # => EnvironmentError: HELLO_WORLD is not a declared dependency
44
46
 
45
47
  ENV['TEST'] = 'overriding'
46
- # => EnvironmentError: TEST is not a declared environment dependency
48
+ # => EnvironmentError: TEST is not a declared dependency
47
49
 
48
- Env.eval do
49
- export 'TEXT', '15', :immutable => true
50
+ Env.instance_eval do
51
+ export 'TEXT', '15'
50
52
  # same as export 'TEXT', '15', :mutable => false
51
53
  end
52
54
 
data/lib/env/load.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative '../env'
2
+ Env.load!
data/lib/env/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Env
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/env.rb CHANGED
@@ -26,6 +26,10 @@ module Env
26
26
  @@env[key] = uri?(value) ? proxify(value) : value
27
27
  end
28
28
 
29
+ def import(key)
30
+ export(key, ENV.get(key))
31
+ end
32
+
29
33
  def load!
30
34
  @@enforced or Env.enforce
31
35
  eval File.read("Envfile") if File.exist?("Envfile")
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/env'
2
+
3
+ describe Env, 'import' do
4
+ def envfile(string)
5
+ File.open("Envfile", 'w') do |f|
6
+ f << string
7
+ end
8
+ end
9
+
10
+ after { File.unlink('Envfile') }
11
+
12
+ context "with an import statement" do
13
+ before do
14
+ ENV['FOO'] = 'bar'
15
+ envfile(%{
16
+ import 'FOO'
17
+ })
18
+ Env.load!
19
+ end
20
+
21
+ it "should use the value in the ENV" do
22
+ ENV['FOO'].should == 'bar'
23
+ end
24
+ end
25
+ end
data/spec/load_spec.rb CHANGED
@@ -7,8 +7,10 @@ describe Env, '::load!' do
7
7
  end
8
8
  end
9
9
 
10
- it "should return false" do
11
- Env.load!.should be_false
10
+ context "with no Envfile" do
11
+ it "should return false" do
12
+ Env.load!.should be_false
13
+ end
12
14
  end
13
15
 
14
16
  context "with a simple Envfile" do
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.1
4
+ version: 0.0.2
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-04 00:00:00.000000000 -07:00
12
+ date: 2011-08-09 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
@@ -27,8 +27,10 @@ files:
27
27
  - Rakefile
28
28
  - env.gemspec
29
29
  - lib/env.rb
30
+ - lib/env/load.rb
30
31
  - lib/env/version.rb
31
32
  - spec/enforce_spec.rb
33
+ - spec/import_spec.rb
32
34
  - spec/load_spec.rb
33
35
  - spec/uri_spec.rb
34
36
  has_rdoc: true
@@ -58,5 +60,6 @@ specification_version: 3
58
60
  summary: Manage your ENV with ease
59
61
  test_files:
60
62
  - spec/enforce_spec.rb
63
+ - spec/import_spec.rb
61
64
  - spec/load_spec.rb
62
65
  - spec/uri_spec.rb