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 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
- ### Declaring Dependecies
23
+ ### Explictly declaring your environment
24
24
 
25
- export "PROVIDER_PASSWORD", '1234', :group => :development, :required => false
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
- ### In your Ruby files
56
+ #### Use
57
+ Env.load!
58
+ -same as-
59
+ Env.load! :default
36
60
 
37
- require 'env'
61
+ Env.load! :default, :test
62
+ ENV['SERVICE_URL'] # => 'http://username:password@example.com/"
38
63
 
39
- Env.load('../path_to_file')
40
- Env.load! # look for Envfile
64
+ Env.load! :development
65
+ ENV['SERVICE_URL'] # => 'http://username:password@www.service.com/path"
41
66
 
42
- ENV['HELLO_WORLD'] # => nil
43
- Env.enforce
44
- ENV['HELLO_WORLD']
45
- # => EnvironmentError: HELLO_WORLD is not a declared dependency
67
+ ### Mutability
46
68
 
47
- ENV['TEST'] = 'overriding'
48
- # => EnvironmentError: TEST is not a declared dependency
69
+ #### Envfile
70
+ export 'TEXT', '15', :mutable => false
71
+ export 'TEXT', '15', :immutable => false
49
72
 
50
- Env.instance_eval do
51
- export 'TEXT', '15'
52
- # same as export 'TEXT', '15', :mutable => false
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
- ### in Envfile
82
+ ### Envfile
61
83
  export "SERVICE", 'http://username:password@example.com/"
62
84
 
63
- ### in your Ruby Script
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
@@ -1,3 +1,3 @@
1
1
  module Env
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
@@ -50,7 +50,7 @@ describe Env, '::import' do
50
50
  Env.load!
51
51
  end
52
52
 
53
- it "should import TMP, TEMP, and RACK" do
53
+ it "should import TMP, TEMP, and :rack" do
54
54
  heroku.each do |var|
55
55
  lambda { ENV[var] }.should_not raise_error
56
56
  end
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
@@ -33,7 +33,7 @@ describe Env, 'uri support' do
33
33
  ENV['FOO'].url.should == 'http://this.domain.example.com'
34
34
  end
35
35
 
36
- it "should respond to #scheme with the scheme'" do
36
+ it "should respond to #scheme with the scheme" do
37
37
  ENV['FOO'].scheme.should == 'http'
38
38
  end
39
39
 
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
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-10 00:00:00.000000000 -07:00
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