appenv 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,44 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
3
3
  def initialize(file = '.env', &blk)
4
4
  super(&nil)
5
5
  @file = file
6
+ expand(&blk)
7
+ end
8
+
9
+
10
+ # You can use `expand` to add more values to the environment after
11
+ # initialization. eg:
12
+ #
13
+ # # Create the environment:
14
+ # @env = AppEnv::Environment.new('test/data/env') { |env, src|
15
+ # env.var1 = src.var_one
16
+ # }
17
+ #
18
+ # # Later, expand it:
19
+ # @env.expand { |env, src|
20
+ # env.var2 = src.var_two
21
+ # }
22
+ #
23
+ def expand(&blk)
6
24
  source = _compile_source_env
7
25
  blk.call(self, source)
8
26
  end
9
27
 
10
28
 
29
+ # If you are computing a complex value (say, a conditional one), you might
30
+ # like to set the value via a block. eg:
31
+ #
32
+ # # Simple variable assignment:
33
+ # env.var1 = src.var_one
34
+ #
35
+ # # Variable assignment with `set`:
36
+ # env.set(:var2) {
37
+ # if abcd?
38
+ # 'xyz'
39
+ # else
40
+ # 'foo'
41
+ # end
42
+ # }
43
+ #
11
44
  def set(property, &blk)
12
45
  self.send("#{property}=", blk.call)
13
46
  end
@@ -29,6 +62,7 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
29
62
  File.open(@file, 'r').each_line { |ln|
30
63
  cln = ln.strip.sub(/^export\s+/, '')
31
64
  next if cln.match(/^#/)
65
+ next if cln.empty?
32
66
  if m = cln.match(/\A([A-Za-z_0-9]+)=(.*)\z/)
33
67
  k = m[1]
34
68
  v = m[2]
@@ -1,5 +1,5 @@
1
1
  module AppEnv
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '1.0.0'
4
4
 
5
5
  end
@@ -15,4 +15,16 @@ class AppEnv::TestEnvironment < Test::Unit::TestCase
15
15
  assert_equal('grault', @env.var3)
16
16
  end
17
17
 
18
+
19
+ def test_expand
20
+ @env = AppEnv::Environment.new('test/data/env') { |env, src|
21
+ env.var1 = src.var_one
22
+ }
23
+ assert_equal('foo', @env.var1)
24
+ @env.expand { |env, src|
25
+ env.var2 = src.var_two
26
+ }
27
+ assert_equal('bar', @env.var2)
28
+ end
29
+
18
30
  end
metadata CHANGED
@@ -1,34 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: appenv
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Joseph Pearson
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2013-06-05 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: activesupport
16
- requirement: &9946620 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: *9946620
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
25
32
  description: Environment-variable compatible application configuration.
26
- email:
33
+ email:
27
34
  - joseph@booki.sh
28
35
  executables: []
36
+
29
37
  extensions: []
38
+
30
39
  extra_rdoc_files: []
31
- files:
40
+
41
+ files:
32
42
  - .gitignore
33
43
  - README.md
34
44
  - Rakefile
@@ -39,31 +49,37 @@ files:
39
49
  - test/data/env
40
50
  - test/test_helper.rb
41
51
  - test/unit/test_environment.rb
42
- homepage: ''
52
+ has_rdoc: true
53
+ homepage: ""
43
54
  licenses: []
55
+
44
56
  post_install_message:
45
57
  rdoc_options: []
46
- require_paths:
58
+
59
+ require_paths:
47
60
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ! '>='
58
- - !ruby/object:Gem::Version
59
- version: '0'
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
60
75
  requirements: []
76
+
61
77
  rubyforge_project:
62
- rubygems_version: 1.8.11
78
+ rubygems_version: 1.3.6
63
79
  signing_key:
64
80
  specification_version: 3
65
81
  summary: Application environment configuration
66
- test_files:
82
+ test_files:
67
83
  - test/data/env
68
84
  - test/test_helper.rb
69
85
  - test/unit/test_environment.rb