vcontainer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +81 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/vcontainer.rb +6 -0
- data/lib/vcontainer/container.rb +48 -0
- data/lib/vcontainer/container_dsl.rb +22 -0
- data/lib/vcontainer/nil_container.rb +15 -0
- data/lib/vcontainer/parent_provider.rb +20 -0
- data/lib/vcontainer/simple_provider.rb +22 -0
- data/lib/vcontainer/singleton_provider.rb +27 -0
- data/spec/acceptance/access_parent_container_spec.rb +34 -0
- data/spec/acceptance/basic_usage_spec.rb +28 -0
- data/spec/acceptance/container_building_spec.rb +15 -0
- data/spec/acceptance/injection_usage_spec.rb +23 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/vcontainer/simple_provider_spec.rb +18 -0
- data/spec/vcontainer/singleton_provider_spec.rb +18 -0
- metadata +178 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "activesupport", ">= 3.0.0"
|
5
|
+
gem "i18n"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.1.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.5.1"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.3)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
i18n (0.5.0)
|
8
|
+
jeweler (1.5.1)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rake (0.8.7)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rcov (0.9.9-java)
|
15
|
+
rspec (2.1.0)
|
16
|
+
rspec-core (~> 2.1.0)
|
17
|
+
rspec-expectations (~> 2.1.0)
|
18
|
+
rspec-mocks (~> 2.1.0)
|
19
|
+
rspec-core (2.1.0)
|
20
|
+
rspec-expectations (2.1.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.1.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
java
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activesupport (>= 3.0.0)
|
30
|
+
bundler (~> 1.0.0)
|
31
|
+
i18n
|
32
|
+
jeweler (~> 1.5.1)
|
33
|
+
rcov
|
34
|
+
rspec (~> 2.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 guilherme silveira & david paniz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= vcontainer
|
2
|
+
|
3
|
+
VContainer is a simple dependency injection framework for Ruby.
|
4
|
+
Dependency injection should be as simple as possible. Whenever you can use the most
|
5
|
+
effective dependecy injection library: "new".
|
6
|
+
|
7
|
+
BasicComponent.new(EmailSender.new)
|
8
|
+
|
9
|
+
Otherwise you can always stick to VContainer as a PicoContainer based implementation for Ruby.
|
10
|
+
The acceptance tests show several different ways to use VContainer.
|
11
|
+
|
12
|
+
Creating a container and requesting an instance:
|
13
|
+
|
14
|
+
class MyComponent
|
15
|
+
end
|
16
|
+
container = VContainer::ContainerDsl.new.register(MyComponent)
|
17
|
+
component = container.provide :my_component
|
18
|
+
|
19
|
+
You can use included modules or type based requests:
|
20
|
+
|
21
|
+
class MyComponent < Component
|
22
|
+
include BasicInfo
|
23
|
+
end
|
24
|
+
container = VContainer::ContainerDsl.new.register(MyComponent)
|
25
|
+
component = container.provide :component
|
26
|
+
component = container.provide :basic_info
|
27
|
+
|
28
|
+
Dependecy injection plays nicely:
|
29
|
+
|
30
|
+
class Dao
|
31
|
+
end
|
32
|
+
class Clients
|
33
|
+
def initialize(dao)
|
34
|
+
@dao = dao
|
35
|
+
end
|
36
|
+
def all
|
37
|
+
@dao.find(:all)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
container = VContainer::ContainerDsl.new.register(Dao, Clients)
|
41
|
+
clients = container.provide :clients
|
42
|
+
|
43
|
+
You can compose containers in order to create different layers of control:
|
44
|
+
|
45
|
+
base = VContainer::ContainerDsl.new.register(dao)
|
46
|
+
container = VContainer::ContainerDsl.new(base).register(Clients)
|
47
|
+
clients = container.provide :clients
|
48
|
+
|
49
|
+
There is also a singleton provider, that instantiates a type only once.
|
50
|
+
|
51
|
+
base = VContainer::ContainerDsl.new
|
52
|
+
base.use VContainer::SingletonProvider.new(Dao)
|
53
|
+
base.provide(:dao)==base.provide(:dao)
|
54
|
+
|
55
|
+
As with any decent container, you can register your own "Adapter/Provider":
|
56
|
+
|
57
|
+
base = VContainer::ContainerDsl.new
|
58
|
+
base.use YourAdapterProviderWhatever.new
|
59
|
+
base.provide(:dao) # will invoke your adapter
|
60
|
+
|
61
|
+
Just check the SimpleProvider, ParentProvider and SingletonProvider examples to roll out your own provider.
|
62
|
+
|
63
|
+
== Team ==
|
64
|
+
|
65
|
+
VContainer was created by Guilherme Silveira and has been developed together with Eric Torti.
|
66
|
+
|
67
|
+
== Contributing to vcontainer
|
68
|
+
|
69
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
70
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
71
|
+
* Fork the project
|
72
|
+
* Start a feature/bugfix branch
|
73
|
+
* Commit and push until you are happy with your contribution
|
74
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
75
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
76
|
+
|
77
|
+
== Copyright
|
78
|
+
|
79
|
+
Copyright (c) 2010 guilherme silveira. See LICENSE.txt for
|
80
|
+
further details.
|
81
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "vcontainer"
|
16
|
+
gem.homepage = "http://github.com/caelum/vcontainer"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A dependency injection framework.}
|
19
|
+
gem.description = %Q{A dependency injection framework based in PicoContainer.}
|
20
|
+
gem.email = "guilherme.silveira@caelum.com.br"
|
21
|
+
gem.authors = ["guilherme silveira & david paniz & eric torti"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "vcontainer #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/vcontainer.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module VContainer
|
4
|
+
|
5
|
+
# A basic container implementation
|
6
|
+
class Container
|
7
|
+
|
8
|
+
def use(provider)
|
9
|
+
providers << provider
|
10
|
+
end
|
11
|
+
|
12
|
+
def provide(what)
|
13
|
+
provider_for(what).build(what, self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def can_provide?(what)
|
17
|
+
provider_for(what) != nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def provide_for_method(method)
|
21
|
+
params = method.parameters
|
22
|
+
has_parameters = params[0]!=[:rest]
|
23
|
+
if has_parameters
|
24
|
+
provide_instances_for(params)
|
25
|
+
else
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def provide_instances_for(params)
|
32
|
+
params.collect do |param|
|
33
|
+
provide(param[1])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def provider_for(what)
|
38
|
+
providers.find {|p| p.can_handle?(what)}
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def providers
|
43
|
+
@providers ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VContainer
|
2
|
+
|
3
|
+
# A basic container implementation
|
4
|
+
class ContainerDsl < Container
|
5
|
+
|
6
|
+
def initialize(parent = NilContainer.new)
|
7
|
+
register ParentProvider.new(parent)
|
8
|
+
end
|
9
|
+
|
10
|
+
def register(*provider)
|
11
|
+
provider.each do |p|
|
12
|
+
if p.kind_of? Class
|
13
|
+
p = VContainer::SimpleProvider.new(p)
|
14
|
+
end
|
15
|
+
use(p)
|
16
|
+
end
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VContainer
|
2
|
+
|
3
|
+
# A simple provider that looks up into a parent to provide something
|
4
|
+
class ParentProvider
|
5
|
+
|
6
|
+
def initialize(parent)
|
7
|
+
@parent = parent
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(what, container = NilContainer.new)
|
11
|
+
@parent.provide(what)
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_handle?(what)
|
15
|
+
@parent.can_provide?(what)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VContainer
|
2
|
+
|
3
|
+
# A simple provider will instantiate a type everytime its required
|
4
|
+
class SimpleProvider
|
5
|
+
|
6
|
+
def initialize(build_type)
|
7
|
+
@type = build_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(what, container = NilContainer.new)
|
11
|
+
values = container.provide_for_method(@type.instance_method(:initialize))
|
12
|
+
@type.new *values
|
13
|
+
end
|
14
|
+
|
15
|
+
def can_handle?(what)
|
16
|
+
expected = what.to_s.camelize.constantize
|
17
|
+
@type.ancestors.include?(expected)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VContainer
|
2
|
+
|
3
|
+
# A singleton provider will only instantiate a type once
|
4
|
+
class SingletonProvider
|
5
|
+
|
6
|
+
def initialize(build_type)
|
7
|
+
@type = build_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(what, container = NilContainer.new)
|
11
|
+
@cached_instance ||= instantiate(container)
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_handle?(what)
|
15
|
+
expected = what.to_s.camelize.constantize
|
16
|
+
@type.ancestors.include?(expected)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def instantiate(container)
|
21
|
+
values = container.provide_for_method(@type.instance_method(:initialize))
|
22
|
+
@type.new *values
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::ParentProvider do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@container = VContainer::ContainerDsl.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "looks up on its parents prior to providing something" do
|
10
|
+
@container.register SimpleEmailSender
|
11
|
+
|
12
|
+
basic_container = VContainer::ContainerDsl.new(@container)
|
13
|
+
basic_container.register BasicComponent
|
14
|
+
|
15
|
+
email_cc = VContainer::ContainerDsl.new(@container)
|
16
|
+
email_cc.register EmailComponent
|
17
|
+
|
18
|
+
basic_container.provide(:component).should be_kind_of(BasicComponent)
|
19
|
+
basic_container.provide(:component).sender.class.should == SimpleEmailSender
|
20
|
+
|
21
|
+
email_cc.provide(:component).should be_kind_of(EmailComponent)
|
22
|
+
email_cc.provide(:component).sender.class.should == SimpleEmailSender
|
23
|
+
end
|
24
|
+
|
25
|
+
it "looks up on its parents prior to providing something" do
|
26
|
+
@container.use VContainer::SingletonProvider.new(SimpleEmailSender)
|
27
|
+
|
28
|
+
basic_container = VContainer::ContainerDsl.new(@container).register(BasicComponent)
|
29
|
+
email_cc = VContainer::ContainerDsl.new(@container).register(EmailComponent)
|
30
|
+
|
31
|
+
basic_container.provide(:component).sender == email_cc.provide(:component).sender
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::SimpleProvider do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@container = VContainer::Container.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "support provider registration and so on" do
|
10
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
11
|
+
@container.provide(SimpleEmailSender).class.should == SimpleEmailSender
|
12
|
+
end
|
13
|
+
|
14
|
+
it "lets us know whether it can handle something" do
|
15
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
16
|
+
@container.can_provide?(SimpleEmailSender).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "support provider registration with symbol" do
|
20
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
21
|
+
@container.provide(:simpleEmailSender).class.should == SimpleEmailSender
|
22
|
+
end
|
23
|
+
|
24
|
+
it "lets us know whether it can handle some symbol" do
|
25
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
26
|
+
@container.can_provide?(:simpleEmailSender).should be_true
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::SimpleProvider do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@container = VContainer::ContainerDsl.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "support straight class registering" do
|
10
|
+
@container.register BasicComponent, SimpleEmailSender
|
11
|
+
basic = @container.provide(:basicComponent)
|
12
|
+
basic.sender.class.should == SimpleEmailSender
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::SimpleProvider do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@container = VContainer::Container.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "support dependency injection when providing a service" do
|
10
|
+
@container.use VContainer::SimpleProvider.new(BasicComponent)
|
11
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
12
|
+
basic = @container.provide(BasicComponent)
|
13
|
+
basic.sender.class.should == SimpleEmailSender
|
14
|
+
end
|
15
|
+
|
16
|
+
it "support dependency injection based on a module" do
|
17
|
+
@container.use VContainer::SimpleProvider.new(EmailComponent)
|
18
|
+
@container.use VContainer::SimpleProvider.new(SimpleEmailSender)
|
19
|
+
basic = @container.provide(EmailComponent)
|
20
|
+
basic.sender.class.should == SimpleEmailSender
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'vcontainer'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
module EmailSender
|
15
|
+
end
|
16
|
+
|
17
|
+
class EmailTemplate
|
18
|
+
end
|
19
|
+
|
20
|
+
class SimpleEmailSender < EmailTemplate
|
21
|
+
include EmailSender
|
22
|
+
end
|
23
|
+
|
24
|
+
class Component
|
25
|
+
end
|
26
|
+
|
27
|
+
class BasicComponent < Component
|
28
|
+
attr_reader :sender
|
29
|
+
def initialize(simpleEmailSender)
|
30
|
+
@sender = simpleEmailSender
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
class EmailComponent < Component
|
36
|
+
attr_reader :sender
|
37
|
+
def initialize(emailSender)
|
38
|
+
@sender = emailSender
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::SimpleProvider do
|
4
|
+
it "always return different instances" do
|
5
|
+
provider = VContainer::SimpleProvider.new(SimpleEmailSender)
|
6
|
+
provider.build(:simpleEmailSender).should_not == provider.build(:simpleEmailSender)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can handle a type's module" do
|
10
|
+
provider = VContainer::SimpleProvider.new(SimpleEmailSender)
|
11
|
+
provider.can_handle?(:emailSender).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can handle a type's superclass" do
|
15
|
+
provider = VContainer::SimpleProvider.new(SimpleEmailSender)
|
16
|
+
provider.can_handle?(:emailTemplate).should be_true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe VContainer::SingletonProvider do
|
4
|
+
it "always return the same singleton instance" do
|
5
|
+
provider = VContainer::SingletonProvider.new(SimpleEmailSender)
|
6
|
+
provider.build(:simpleEmailSender).should == provider.build(:simpleEmailSender)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can handle a type's module" do
|
10
|
+
provider = VContainer::SingletonProvider.new(SimpleEmailSender)
|
11
|
+
provider.can_handle?(:emailSender).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can handle a type's superclass" do
|
15
|
+
provider = VContainer::SingletonProvider.new(SimpleEmailSender)
|
16
|
+
provider.can_handle?(:emailTemplate).should be_true
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcontainer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- guilherme silveira & david paniz & eric torti
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-07 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 3.0.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: i18n
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 1
|
58
|
+
- 0
|
59
|
+
version: 2.1.0
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bundler
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 1
|
72
|
+
- 0
|
73
|
+
- 0
|
74
|
+
version: 1.0.0
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 5
|
88
|
+
- 1
|
89
|
+
version: 1.5.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: rcov
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: *id006
|
106
|
+
description: A dependency injection framework based in PicoContainer.
|
107
|
+
email: guilherme.silveira@caelum.com.br
|
108
|
+
executables: []
|
109
|
+
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files:
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.rdoc
|
115
|
+
files:
|
116
|
+
- .document
|
117
|
+
- .rspec
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.rdoc
|
122
|
+
- Rakefile
|
123
|
+
- VERSION
|
124
|
+
- lib/vcontainer.rb
|
125
|
+
- lib/vcontainer/container.rb
|
126
|
+
- lib/vcontainer/container_dsl.rb
|
127
|
+
- lib/vcontainer/nil_container.rb
|
128
|
+
- lib/vcontainer/parent_provider.rb
|
129
|
+
- lib/vcontainer/simple_provider.rb
|
130
|
+
- lib/vcontainer/singleton_provider.rb
|
131
|
+
- spec/acceptance/access_parent_container_spec.rb
|
132
|
+
- spec/acceptance/basic_usage_spec.rb
|
133
|
+
- spec/acceptance/container_building_spec.rb
|
134
|
+
- spec/acceptance/injection_usage_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/vcontainer/simple_provider_spec.rb
|
137
|
+
- spec/vcontainer/singleton_provider_spec.rb
|
138
|
+
has_rdoc: true
|
139
|
+
homepage: http://github.com/caelum/vcontainer
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: -248008717
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
version: "0"
|
164
|
+
requirements: []
|
165
|
+
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.3.7
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: A dependency injection framework.
|
171
|
+
test_files:
|
172
|
+
- spec/acceptance/access_parent_container_spec.rb
|
173
|
+
- spec/acceptance/basic_usage_spec.rb
|
174
|
+
- spec/acceptance/container_building_spec.rb
|
175
|
+
- spec/acceptance/injection_usage_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/vcontainer/simple_provider_spec.rb
|
178
|
+
- spec/vcontainer/singleton_provider_spec.rb
|