dim 1.1.0 → 1.2.0

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dim (1.0.0)
4
+ dim (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.markdown CHANGED
@@ -54,8 +54,9 @@ The following could be in a "lib.init.rb" file or in a Rails app, "config/initia
54
54
  Logger.new(c.log_file_path)
55
55
  end
56
56
 
57
- # attempts to read ENV["API_PASSWORD"], returns "FAKE_PASSWORD" if it can't be found
58
- ServerContainer.register_env(:api_password,"FAKE_PASSWORD")
57
+ # attempts to read ENV["API_PASSWORD"], otherwise makes sure that the parent container has
58
+ # a service named api_password registered
59
+ ServerContainer.register_env(:api_password)
59
60
 
60
61
  Using the above code elsewhere in the app, when you want a reference to the app's logger object:
61
62
 
data/lib/dim.rb CHANGED
@@ -1,10 +1,10 @@
1
- #!/usr/bin/env ruby
2
1
  #--
3
- # Copyright 2004, 2005, 2010 by Jim Weirich (jim.weirich@gmail.com).
2
+ # Copyright 2004, 2005, 2010, 2012 by Jim Weirich (jim.weirich@gmail.com)
3
+ # and Mike Subelsky (mike@subelsky.com)
4
+ #
4
5
  # All rights reserved.
5
6
  #
6
- # This software is available under the MIT license. See the
7
- # MIT-LICENSE file for details.
7
+ # This software is available under the MIT license. See the LICENSE file for details.
8
8
  #++
9
9
  #
10
10
  # = Dependency Injection - Minimal (DIM)
@@ -64,11 +64,17 @@ module Dim
64
64
  @services[name] = block
65
65
  end
66
66
 
67
- # Lookup a service from ENV variables; fall back to searching the provided hash
68
- # if the
69
- def register_env(name,default = nil)
70
- value = ENV[name.to_s.upcase] || default || raise(EnvironmentVariableNotFound, "Cannot find any ENV variable named #{name}")
71
- register(name) { value }
67
+ # Lookup a service from ENV variables; fall back to searching the container and its parents for a default value
68
+ def register_env(name)
69
+ if value = ENV[name.to_s.upcase]
70
+ register(name) { value }
71
+ else
72
+ begin
73
+ @parent.service_block(name)
74
+ rescue MissingServiceError
75
+ raise EnvironmentVariableNotFound, "Could not find an ENV variable named #{name.to_s.upcase} nor could we find a service named #{name} in the parent container"
76
+ end
77
+ end
72
78
  end
73
79
 
74
80
  # Lookup a service by name. Throw an exception if no service is
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dim
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/spec/dim_spec.rb CHANGED
@@ -170,9 +170,13 @@ describe Dim::Container do
170
170
  end
171
171
 
172
172
  Scenario "which exist in optional hash" do
173
- Given { ENV["SHAZ"] = nil }
174
- Given { container.register_env(:shaz,"test-bot") }
175
- Then { container.shaz.should == "test-bot" }
173
+ Given(:parent) { container }
174
+ Given { parent.register(:foo) { "bar" } }
175
+ Given(:child) { Dim::Container.new(parent) }
176
+
177
+ Given { ENV["FOO"] = nil }
178
+ Given { child.register_env(:foo) }
179
+ Then { container.foo.should == "bar" }
176
180
  end
177
181
 
178
182
  Scenario "which don't exist in optional hash" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dim
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: