dependor 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dependor (1.0.0)
4
+ dependor (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,17 +1,18 @@
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 :CustomizedInjector, 'dependor/customized_injector'
8
- autoload :EvaluatingInjector, 'dependor/evaluating_injector'
9
- autoload :Injectable, 'dependor/injectable'
10
- autoload :Instantiator, 'dependor/instantiator'
11
- autoload :Isolate, 'dependor/isolate'
12
- autoload :Let, 'dependor/let'
13
- autoload :SendingInjector, 'dependor/sending_injector'
14
- autoload :Shorty, 'dependor/shorty'
15
- autoload :UnknownObject, 'dependor/exceptions'
16
- 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 :DependencyNamesCache, 'dependor/dependency_names_cache'
9
+ autoload :EvaluatingInjector, 'dependor/evaluating_injector'
10
+ autoload :Injectable, 'dependor/injectable'
11
+ autoload :Instantiator, 'dependor/instantiator'
12
+ autoload :Isolate, 'dependor/isolate'
13
+ autoload :Let, 'dependor/let'
14
+ autoload :SendingInjector, 'dependor/sending_injector'
15
+ autoload :Shorty, 'dependor/shorty'
16
+ autoload :UnknownObject, 'dependor/exceptions'
17
+ autoload :VERSION, 'dependor/version'
17
18
  end
@@ -24,14 +24,18 @@ module Dependor
24
24
 
25
25
  def inject(klass, overrides = {})
26
26
  injector = Dependor::CustomizedInjector.new(auto_injector, overrides)
27
- instantiator = Dependor::Instantiator.new(injector)
27
+ instantiator = Dependor::Instantiator.new(injector, dependency_names)
28
28
  instantiator.instantiate(klass)
29
29
  end
30
30
 
31
31
  private
32
32
 
33
33
  def auto_injector
34
- @auto_injector ||= Dependor::AutoInjector.new(self, self.class.search_modules)
34
+ @auto_injector ||= Dependor::AutoInjector.new(self, dependency_names, self.class.search_modules)
35
+ end
36
+
37
+ def dependency_names
38
+ @dependency_names ||= Dependor::DependencyNamesCache.new
35
39
  end
36
40
 
37
41
  end
@@ -1,9 +1,9 @@
1
1
  module Dependor
2
2
  class AutoInjector
3
3
 
4
- def initialize(injector, search_modules)
4
+ def initialize(injector, dependency_names, search_modules)
5
5
  @injector = injector
6
- @instantiator = Instantiator.new(self)
6
+ @instantiator = Instantiator.new(self, dependency_names)
7
7
  @class_name_resolver = ClassNameResolver.new(search_modules)
8
8
  end
9
9
 
@@ -0,0 +1,18 @@
1
+ module Dependor
2
+ class DependencyNamesCache
3
+ def initialize
4
+ @constructor_params = {}
5
+ end
6
+
7
+ def for_class(klass)
8
+ @constructor_params[klass] ||= get_constructor_params(klass)
9
+ end
10
+
11
+ private
12
+
13
+ def get_constructor_params(klass)
14
+ params = klass.instance_method(:initialize).parameters
15
+ params.select{|type, name| type == :req}.map{|type, name| name}
16
+ end
17
+ end
18
+ end
@@ -1,24 +1,15 @@
1
1
  module Dependor
2
2
  class Instantiator
3
- def initialize(injector)
3
+ attr_reader :dependency_names
4
+
5
+ def initialize(injector, dependency_names)
4
6
  @injector = injector
5
- @constructor_params = {}
7
+ @dependency_names = dependency_names
6
8
  end
7
9
 
8
10
  def instantiate(klass)
9
- dependencies = dependecy_names_for(klass).map{|name| @injector.get(name)}
11
+ dependencies = dependency_names.for_class(klass).map{|name| @injector.get(name)}
10
12
  return klass.new(*dependencies)
11
13
  end
12
-
13
- private
14
-
15
- def dependecy_names_for(klass)
16
- @constructor_params[klass] ||= get_constructor_params(klass)
17
- end
18
-
19
- def get_constructor_params(klass)
20
- params = klass.instance_method(:initialize).parameters
21
- params.select{|type, name| type == :req}.map{|type, name| name}
22
- end
23
14
  end
24
15
  end
@@ -9,7 +9,8 @@ module Dependor
9
9
  sending_injector = SendingInjector.new(self)
10
10
  injector = CustomizedInjector.new(sending_injector, overrides)
11
11
  end
12
- instantiator = Instantiator.new(injector)
12
+ dependecy_names = DependencyNamesCache.new
13
+ instantiator = Instantiator.new(injector, dependecy_names)
13
14
  instantiator.instantiate(klass)
14
15
  end
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module Dependor
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Dependor::Instantiator do
4
4
  let(:injector) { double(:injector) }
5
- let(:instantiator) { Dependor::Instantiator.new(injector) }
5
+ let(:dependency_names) { Dependor::DependencyNamesCache.new }
6
+ let(:instantiator) { Dependor::Instantiator.new(injector, dependency_names) }
6
7
 
7
8
  it "instantiates objects with no-arg constructors" do
8
9
  klass = Class.new do
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: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -148,6 +148,7 @@ files:
148
148
  - lib/dependor/class_name_resolver.rb
149
149
  - lib/dependor/constructor.rb
150
150
  - lib/dependor/customized_injector.rb
151
+ - lib/dependor/dependency_names_cache.rb
151
152
  - lib/dependor/evaluating_injector.rb
152
153
  - lib/dependor/exceptions.rb
153
154
  - lib/dependor/injectable.rb
@@ -184,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  segments:
186
187
  - 0
187
- hash: -1538921079382714093
188
+ hash: -3867103565292776709
188
189
  required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  none: false
190
191
  requirements:
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  segments:
195
196
  - 0
196
- hash: -1538921079382714093
197
+ hash: -3867103565292776709
197
198
  requirements: []
198
199
  rubyforge_project: dependor
199
200
  rubygems_version: 1.8.25