carb-inject 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e7e8fdd6dec580c4ea33d02cfb2796409c964c9
4
- data.tar.gz: 941f73b2350fc7f498d50d09e0dafdb5760a7f2c
3
+ metadata.gz: ec9c33b40226c4f3d929c3140246ece906a9aa88
4
+ data.tar.gz: b50a7e143d39e3f4b41a4f979ff21ec6f72044cc
5
5
  SHA512:
6
- metadata.gz: 0e22b75b3e7d5790ced046f8637ea6bbaa0431a04e18bfaea3a686921dd00685a343e11c38241fa3227300b4101b0f59d5206ab03e38e9df7aa169f31c154c93
7
- data.tar.gz: 2d8bfe0487510f41c98f1883e838d395c4c48cc29b1530452ddf359a18fa4410d33cac3be340bff71109c70f545a1f79a19d0972a7553746e57bf9c10504a951
6
+ metadata.gz: 1a109b1c64627bfb59ae24b026dd1d651e80ce984e04331c379ca28214dfa678d07361c001260b31914f3fe2fd5c5567a65ea062c1cadd1dc937ce2da3575e53
7
+ data.tar.gz: 68a6d7d6253e959ac084420b757b5ea7d4085868d3a0c596552053659692266ed988b878522ee69eb60e0126137c1b495b0bc3a753bd00c2d8e855039f9243ac
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  `carb-inject` is an utility library for automated dependency injection.
4
4
  Together with a generic container (even a simple `Hash`!), it will cover all
5
- the needs for an IoC container.
5
+ the needs for an IoC container. Check out
6
+ [carb-container](https://github.com/Carburetor/carb-container) for more
7
+ advanced ones.
6
8
 
7
9
  ## Installation
8
10
 
@@ -67,10 +69,10 @@ Or install it yourself as:
67
69
  ## Usage
68
70
 
69
71
  First you'll need a container object.
70
- [dry-container](https://github.com/dry-rb/dry-container) will do the trick,
71
- otherwise just check the implementation of
72
- [Carb::SimpleContainer](https://github.com/Carburetor/carb-inject/blob/b3e9fea68672284aff53c8b78ba0064474d94021/spec/support/simple_container.rb) in
73
- tests
72
+ [carb-container](https://github.com/Carburetor/carb-container) provides a
73
+ simple `RegistryContainer` which you can use.
74
+ Alternatively, you can use a simple ruby hashmap, or use `carb-inject` in an
75
+ entirely [containerless fashion](#passing-lambdas)
74
76
 
75
77
  ```ruby
76
78
  container = { name: "john", age: 30 }
@@ -232,12 +234,11 @@ john.hello # => Hello I'm John Snow, 30 years old
232
234
 
233
235
  ## Features
234
236
 
235
- - Supports inheritance (as long as you call `super`)
237
+ - Supports inheritance
236
238
  - Can write your own injector if you don't like the syntax of the existing one
237
239
  - Can alias dependencies
238
- - Supports any container which responds to `[]`
239
- - Can write your own initializer with your own arguments (as long as you call
240
- `super`)
240
+ - Supports any container which responds to `[]` and `has_key?`
241
+ - Can write your own initializer with your own arguments
241
242
 
242
243
  ## Development
243
244
 
@@ -20,7 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "carb-core", ">= 1.0.0"
23
+ spec.add_dependency "carb-container", ">= 0.1.0"
24
+ spec.add_dependency "carb-core", ">= 1.0.0"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.13"
26
27
  spec.add_development_dependency "rake", "~> 11.0"
@@ -3,7 +3,6 @@ require "carb/inject/dependency_list_cache_name"
3
3
  require "carb/inject/dependency_list"
4
4
  require "carb/inject/injectable"
5
5
  require "carb/inject/injector"
6
- require "carb/inject/dependency_missing_error"
7
6
 
8
7
  module Carb
9
8
  module Inject
@@ -1,8 +1,8 @@
1
1
  require "carb"
2
2
  require "carb/inject/dependency_list"
3
- require "carb/inject/error_container"
4
- require "carb/inject/delegate_container"
5
- require "carb/inject/callable_container"
3
+ require "carb/container/error_container"
4
+ require "carb/container/delegate_container"
5
+ require "carb/container/registry_container"
6
6
 
7
7
  module Carb::Inject
8
8
  # Creates an injector with the specified container
@@ -22,7 +22,7 @@ module Carb::Inject
22
22
  # injects dependencies by including {::Carb::Inject::AutoInjectable},
23
23
  # false by default
24
24
  def initialize(container = nil, auto_inject = false)
25
- @container = container || ErrorContainer.new
25
+ @container = container || ::Carb::Container::ErrorContainer.new
26
26
  @auto_inject = auto_inject
27
27
  end
28
28
 
@@ -51,8 +51,8 @@ module Carb::Inject
51
51
  private
52
52
 
53
53
  def build_delegate(container, lambdas)
54
- callable = CallableContainer.new(lambdas)
55
- DelegateContainer.new(callable, container)
54
+ registry = ::Carb::Container::RegistryContainer.new(lambdas)
55
+ ::Carb::Container::DelegateContainer.new([registry, container])
56
56
  end
57
57
 
58
58
  def merge_dependencies(dependencies, aliased_dependencies)
@@ -1,5 +1,5 @@
1
1
  module Carb
2
2
  module Inject
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carb-inject
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: carb-container
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: carb-core
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,12 +114,8 @@ files:
100
114
  - lib/carb-inject.rb
101
115
  - lib/carb/inject.rb
102
116
  - lib/carb/inject/auto_injectable.rb
103
- - lib/carb/inject/callable_container.rb
104
- - lib/carb/inject/delegate_container.rb
105
117
  - lib/carb/inject/dependency_list.rb
106
118
  - lib/carb/inject/dependency_list_cache_name.rb
107
- - lib/carb/inject/dependency_missing_error.rb
108
- - lib/carb/inject/error_container.rb
109
119
  - lib/carb/inject/injectable.rb
110
120
  - lib/carb/inject/injector.rb
111
121
  - lib/carb/inject/store_dependencies.rb
@@ -129,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
139
  version: '0'
130
140
  requirements: []
131
141
  rubyforge_project:
132
- rubygems_version: 2.6.10
142
+ rubygems_version: 2.6.12
133
143
  signing_key:
134
144
  specification_version: 4
135
145
  summary: Utility for automatic dependency injection
@@ -1,35 +0,0 @@
1
- require "carb"
2
- require "carb/inject/dependency_missing_error"
3
-
4
- module Carb::Inject
5
- # Simple container for holding dependency hashmap with Lambda callable values
6
- class CallableContainer
7
- private
8
-
9
- attr_reader :dependencies
10
-
11
- public
12
-
13
- # @param dependencies [Hash{Object => Proc}] dependency name with proc
14
- # as value, which will be `call`ed to extract the dependency
15
- def initialize(dependencies)
16
- @dependencies = dependencies
17
- end
18
-
19
- # @param name [Object] dependency name
20
- # @return [Object] dependency for given name, obtained by calling lambda
21
- # @raise [DependencyMissingError]
22
- def [](name)
23
- return dependencies[name].call if has_key?(name)
24
-
25
- error_class = ::Carb::Inject::DependencyMissingError
26
- raise error_class.new(name), format(error_class::MESSAGE, name.to_s)
27
- end
28
-
29
- # @param name [Object] dependency name
30
- # @return [Boolean] true if dependency is present, false otherwise
31
- def has_key?(name)
32
- dependencies.has_key?(name)
33
- end
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- require "carb"
2
- require "carb/inject/dependency_missing_error"
3
-
4
- module Carb::Inject
5
- # Container which requests dependency in sequence to a list of containers
6
- # otherwise and if none returns, it raises
7
- class DelegateContainer
8
- private
9
-
10
- attr_reader :containers
11
-
12
- public
13
-
14
- # @param containers [Array<#[], #has_key?>] Must have at least one
15
- # container
16
- def initialize(*containers)
17
- @containers = containers
18
-
19
- if containers.size < 1
20
- raise ArgumentError, "At least one container is required"
21
- end
22
- end
23
-
24
- # @param name [Object] dependency name
25
- # @return [Object] dependency for given name if present in any container
26
- # (only the first in sequence is returned), otherwise raises
27
- # @raise [DependencyMissingError]
28
- def [](name)
29
- containers.each do |container|
30
- return container[name] if container.has_key?(name)
31
- end
32
-
33
- error_class = ::Carb::Inject::DependencyMissingError
34
- raise error_class.new(name), format(error_class::MESSAGE, name.to_s)
35
- end
36
-
37
- # @param name [Object] dependency name
38
- # @return [Boolean] true if dependency is present in any container, false
39
- # otherwise
40
- def has_key?(name)
41
- containers.any? { |container| container.has_key?(name) }
42
- end
43
- end
44
- end
@@ -1,13 +0,0 @@
1
- require "carb"
2
-
3
- module Carb::Inject
4
- class DependencyMissingError < StandardError
5
- MESSAGE = "Dependency %s can't be fetched".freeze
6
-
7
- attr_reader :name
8
-
9
- def initialize(name)
10
- @name = name
11
- end
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- require "carb"
2
- require "carb/inject/dependency_missing_error"
3
-
4
- module Carb::Inject
5
- # Container which holds no dependency and will raise every time
6
- # one is being fetched
7
- class ErrorContainer
8
- # This method will always raise an error
9
- # @param name [Object] dependency name
10
- # @raise [::Carb::Inject::DependencyMissingError] raised
11
- # whenever a dependency is being fetched from this container
12
- def [](name)
13
- error_class = ::Carb::Inject::DependencyMissingError
14
- raise error_class.new(name), format(error_class::MESSAGE, name.to_s)
15
- end
16
-
17
- # @param name [Object] dependency name
18
- # @return [false]
19
- def has_key?(name)
20
- false
21
- end
22
- end
23
- end