dependor 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.pelusa.yml ADDED
@@ -0,0 +1 @@
1
+ sources: lib/**/*.rb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dependor (0.0.1)
4
+ dependor (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -15,6 +15,7 @@ GEM
15
15
  guard-rspec (0.6.0)
16
16
  guard (>= 0.10.0)
17
17
  libnotify (0.7.2)
18
+ rake (0.9.2.2)
18
19
  rspec (2.5.0)
19
20
  rspec-core (~> 2.5.0)
20
21
  rspec-expectations (~> 2.5.0)
@@ -34,4 +35,5 @@ DEPENDENCIES
34
35
  guard
35
36
  guard-rspec
36
37
  libnotify
38
+ rake
37
39
  rspec
data/dependor.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency 'guard-rspec'
21
21
  s.add_development_dependency 'growl'
22
22
  s.add_development_dependency 'libnotify'
23
+ s.add_development_dependency 'rake'
23
24
 
24
25
  s.files = `git ls-files`.split("\n")
25
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/dependor.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require 'dependor/constructor'
2
2
 
3
3
  module Dependor
4
- autoload :AutoInject, 'dependor/auto_inject'
5
- autoload :AutoInjector, 'dependor/auto_injector'
6
- autoload :ClassNameResolver, 'dependor/class_name_resolver'
7
- autoload :Injectable, 'dependor/injectable'
8
- autoload :Instantiator, 'dependor/instantiator'
9
- autoload :Let, 'dependor/let'
10
- autoload :Shorty, 'dependor/shorty'
11
- autoload :UnknownObject, 'dependor/exceptions'
12
- autoload :VERSION, 'dependor/version'
4
+ autoload :AutoInject, 'dependor/auto_inject'
5
+ autoload :AutoInjector, 'dependor/auto_injector'
6
+ autoload :ClassNameResolver, 'dependor/class_name_resolver'
7
+ autoload :CustomizedInjector, 'dependor/customized_injector'
8
+ autoload :Injectable, 'dependor/injectable'
9
+ autoload :Instantiator, 'dependor/instantiator'
10
+ autoload :Let, 'dependor/let'
11
+ autoload :Shorty, 'dependor/shorty'
12
+ autoload :UnknownObject, 'dependor/exceptions'
13
+ autoload :VERSION, 'dependor/version'
13
14
  end
@@ -1,6 +1,5 @@
1
1
  module Dependor
2
2
  module AutoInject
3
-
4
3
  module ClassMethods
5
4
  def look_in_modules(*modules)
6
5
  search_modules.concat(modules)
@@ -23,6 +22,12 @@ module Dependor
23
22
  auto_injector.resolvable?(name)
24
23
  end
25
24
 
25
+ def inject(klass, overrides = {})
26
+ injector = Dependor::CustomizedInjector.new(auto_injector, overrides)
27
+ instantiator = Dependor::Instantiator.new(injector)
28
+ instantiator.instantiate(klass)
29
+ end
30
+
26
31
  private
27
32
 
28
33
  def auto_injector
@@ -0,0 +1,11 @@
1
+ class Dependor::CustomizedInjector
2
+ def initialize(injector, customizations)
3
+ @injector = injector
4
+ @customizations = customizations
5
+ end
6
+
7
+ def get(name)
8
+ return @customizations[name] if @customizations.key?(name)
9
+ return @injector.get(name)
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Dependor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/pelusa.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ rvm rbx exec pelusa
@@ -19,6 +19,15 @@ describe Dependor::AutoInject do
19
19
  end
20
20
  end
21
21
 
22
+ class SomeFactory
23
+ attr_reader :foo, :sample_class_with_no_dependencies
24
+
25
+ def initialize(foo, sample_class_with_no_dependencies)
26
+ @foo = foo
27
+ @sample_class_with_no_dependencies = sample_class_with_no_dependencies
28
+ end
29
+ end
30
+
22
31
  class SampleInjector
23
32
  include Dependor::AutoInject
24
33
  look_in_modules SomeModule
@@ -26,6 +35,10 @@ describe Dependor::AutoInject do
26
35
  def manual_dep
27
36
  "manual dep"
28
37
  end
38
+
39
+ def create_foo(foo_name)
40
+ inject(SomeFactory, foo: foo_name)
41
+ end
29
42
  end
30
43
 
31
44
  let(:injector) { SampleInjector.new }
@@ -68,6 +81,16 @@ describe Dependor::AutoInject do
68
81
  it_behaves_like 'dependency injector'
69
82
  end
70
83
 
84
+ context 'autoinjecting with custom dependencies' do
85
+ it "injects the dependencies which are not explicitly specified" do
86
+ injector.create_foo("the foo name").sample_class_with_no_dependencies.should be_an_instance_of(SampleClassWithNoDependencies)
87
+ end
88
+
89
+ it "passes through the dependencies that were specified" do
90
+ injector.create_foo("the foo name").foo.should == "the foo name"
91
+ end
92
+ end
93
+
71
94
  it "raises an error if the object is not found" do
72
95
  proc{ injector.unknown_object }.should raise_exception(Dependor::UnknownObject)
73
96
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dependor::CustomizedInjector do
4
+ let(:other_injector) { stub }
5
+
6
+ it "returns the customized dependency if given" do
7
+ injector = Dependor::CustomizedInjector.new(other_injector, foo: 'hello')
8
+
9
+ injector.get(:foo).should == 'hello'
10
+ end
11
+
12
+ it "returns the customized dependency even if nil" do
13
+ injector = Dependor::CustomizedInjector.new(other_injector, foo: nil)
14
+
15
+ injector.get(:foo).should be_nil
16
+ end
17
+
18
+ it "delegates to the other injector" do
19
+ other_injector.should_receive(:get).with(:foo).and_return(:the_foo)
20
+
21
+ injector = Dependor::CustomizedInjector.new(other_injector, bar: 'a')
22
+
23
+ injector.get(:foo).should == :the_foo
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependor
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,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &71879150 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *71879150
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: guard
27
- requirement: &71878830 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *71878830
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: guard-rspec
38
- requirement: &71878470 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *71878470
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: growl
49
- requirement: &71878150 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *71878150
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: libnotify
60
- requirement: &71877780 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,28 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *71877780
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  description: Dependor is not a framework for Dependency Injection, but something thatt
70
111
  reduces duplication a little bit when doing manual dependency injection in settings
71
112
  like Rails apps.
@@ -76,6 +117,7 @@ extensions: []
76
117
  extra_rdoc_files: []
77
118
  files:
78
119
  - .gitignore
120
+ - .pelusa.yml
79
121
  - .travis.yml
80
122
  - Gemfile
81
123
  - Gemfile.lock
@@ -89,15 +131,18 @@ files:
89
131
  - lib/dependor/auto_injector.rb
90
132
  - lib/dependor/class_name_resolver.rb
91
133
  - lib/dependor/constructor.rb
134
+ - lib/dependor/customized_injector.rb
92
135
  - lib/dependor/exceptions.rb
93
136
  - lib/dependor/injectable.rb
94
137
  - lib/dependor/instantiator.rb
95
138
  - lib/dependor/let.rb
96
139
  - lib/dependor/shorty.rb
97
140
  - lib/dependor/version.rb
141
+ - pelusa.sh
98
142
  - spec/dependor/auto_inject_spec.rb
99
143
  - spec/dependor/class_name_resolver_spec.rb
100
144
  - spec/dependor/constructor_spec.rb
145
+ - spec/dependor/customized_injector_spec.rb
101
146
  - spec/dependor/injectable_spec.rb
102
147
  - spec/dependor/instantiator_spec.rb
103
148
  - spec/dependor/let_spec.rb
@@ -117,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
162
  version: '0'
118
163
  segments:
119
164
  - 0
120
- hash: 637782349
165
+ hash: -493455405
121
166
  required_rubygems_version: !ruby/object:Gem::Requirement
122
167
  none: false
123
168
  requirements:
@@ -126,10 +171,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
171
  version: '0'
127
172
  segments:
128
173
  - 0
129
- hash: 637782349
174
+ hash: -493455405
130
175
  requirements: []
131
176
  rubyforge_project: dependor
132
- rubygems_version: 1.8.10
177
+ rubygems_version: 1.8.24
133
178
  signing_key:
134
179
  specification_version: 3
135
180
  summary: A couple of classes and modules that simplify dependency injection in Ruby.