dependor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dependor (0.0.2)
4
+ dependor (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -10,14 +10,17 @@ module Dependor
10
10
  def get(name)
11
11
  ensure_resolvable!(name)
12
12
 
13
- return @injector.send(name) if method_exists?(name)
13
+ if has_method?(name)
14
+ return @injector.send(name) if no_arguments?(name)
15
+ return @injector.method(name).to_proc
16
+ end
14
17
 
15
18
  klass = @class_name_resolver.for_name(name)
16
19
  @instantiator.instantiate(klass)
17
20
  end
18
21
 
19
22
  def resolvable?(name)
20
- method_exists?(name) || !!@class_name_resolver.for_name(name)
23
+ has_method?(name) || !!@class_name_resolver.for_name(name)
21
24
  end
22
25
 
23
26
  private
@@ -28,10 +31,14 @@ module Dependor
28
31
  end
29
32
  end
30
33
 
31
- def method_exists?(name)
34
+ def has_method?(name)
32
35
  @injector.methods.include?(name)
33
36
  end
34
37
 
38
+ def no_arguments?(name)
39
+ @injector.method(name).arity == 0
40
+ end
41
+
35
42
  end
36
43
 
37
44
  end
@@ -1,3 +1,3 @@
1
1
  module Dependor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,6 +14,10 @@ describe Dependor::AutoInject do
14
14
  takes :manual_dep
15
15
  end
16
16
 
17
+ class DependsOnFactoryMethod
18
+ takes :create_foo
19
+ end
20
+
17
21
  module SomeModule
18
22
  class SampleClassWithinSomeModule
19
23
  end
@@ -91,6 +95,14 @@ describe Dependor::AutoInject do
91
95
  end
92
96
  end
93
97
 
98
+ context 'injecting factory methods' do
99
+ it "injects factory methods as procs" do
100
+ object = injector.depends_on_factory_method
101
+
102
+ object.create_foo.call("test").foo.should == "test"
103
+ end
104
+ end
105
+
94
106
  it "raises an error if the object is not found" do
95
107
  proc{ injector.unknown_object }.should raise_exception(Dependor::UnknownObject)
96
108
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: -493455405
165
+ hash: -216139779
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: -493455405
174
+ hash: -216139779
175
175
  requirements: []
176
176
  rubyforge_project: dependor
177
177
  rubygems_version: 1.8.24