unity-dependency-container 1.1.0 → 1.1.1

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
  SHA256:
3
- metadata.gz: 95ecbf88cb30fe3a940f14fecab38aac375994201c59fccbe9669a403505685a
4
- data.tar.gz: c6a856fbb143079767b55d7f44ae31203269eb768f9dfe91c5016befd0428a20
3
+ metadata.gz: edd4f4aa089af94042a2e8f85b178ab549fdf671811d3aeedd71eea177476f35
4
+ data.tar.gz: c38db2936eb013401b01a7903a44d1946070f90512f9eb74f473f08e974f6217
5
5
  SHA512:
6
- metadata.gz: c53afd56a4df8801ffbcadfa3019d1d79ca49b397eb91fc201974553c6264bf9afb6942c18094cbaac455840db2b5933b3f8b3c46b120cfedbedfb834dd292ed
7
- data.tar.gz: 775347c35a72973fa59ec0497e02bf4a6386878b8b737c9d6bc67f308f56b9bbee1720c5146fde68643d41059cd6a29610250eed1afa463ca5aa191362a2f693
6
+ metadata.gz: 630bcc823bf1155ccd7215386c90f9e10493228eb322c2356cc9a8f95e421288379b4eaad69db1f8e08e5ffbaf6019326647b8f344254238d31e12a90de61962
7
+ data.tar.gz: b5a67c0ec0f5fd62b225e40bfb31546b052b161f99ce1c287b0ebca0ac1d5138000e86b17fc4e0958d62e1dfab8779f63acf5e182c15d569d7d050c7c4654773
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unity-dependency-container (1.0.0)
4
+ unity-dependency-container (1.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,6 +9,7 @@ GEM
9
9
  rake (13.0.6)
10
10
 
11
11
  PLATFORMS
12
+ arm64-darwin-21
12
13
  x86_64-darwin-20
13
14
 
14
15
  DEPENDENCIES
@@ -16,4 +17,4 @@ DEPENDENCIES
16
17
  unity-dependency-container!
17
18
 
18
19
  BUNDLED WITH
19
- 2.2.30
20
+ 2.3.3
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Unity::DependencyContainer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/unity/dependency_container`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Simple thread-safe dependency injection.
6
4
 
7
5
  ## Installation
8
6
 
@@ -12,24 +10,35 @@ Add this line to your application's Gemfile:
12
10
  gem 'unity-dependency-container'
13
11
  ```
14
12
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install unity-dependency-container
22
-
23
13
  ## Usage
24
14
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unity-dependency-container.
15
+ ```ruby
16
+ class CalculatorService
17
+ def sum(a, b)
18
+ a + b
19
+ end
20
+ end
21
+
22
+ module Foo
23
+ extend Unity::DependencyContainer
24
+
25
+ dependency 'services.calculator' do
26
+ CalculatorService.new
27
+ end
28
+
29
+ # you can also use Symbol as dependencies' names
30
+ dependency :calculator do
31
+ CalculatorService.new
32
+ end
33
+ end
34
+
35
+ a = Foo.di('services.calculator').sum(1, 2)
36
+ b = Foo.with_dependency('services.calculator') do |dep|
37
+ dep.sum(1, 2)
38
+ end
39
+ c = Foo.with_dependency(:calculator) { |dep| dep.sum(1, 2) }
40
+
41
+ puts a # => 3
42
+ puts b # => 3
43
+ puts c # => 3
44
+ ```
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unity
4
4
  module DependencyContainer
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
@@ -25,6 +25,10 @@ module Unity
25
25
  Thread.current[:di_instances][name] = di_container_repository[name].call
26
26
  end
27
27
 
28
+ def with_dependency(name, &block)
29
+ yield(di(name))
30
+ end
31
+
28
32
  def dependency(name, &block)
29
33
  di_container_repository[name] = block
30
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unity-dependency-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - saluzafa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Extend module/class abilities to provide dependencies container/injection
14
14
  email:
@@ -27,7 +27,6 @@ files:
27
27
  - lib/unity-dependency-container.rb
28
28
  - lib/unity/dependency_container.rb
29
29
  - lib/unity/dependency_container/version.rb
30
- - unity-dependency-container-1.0.0.gem
31
30
  homepage: https://github.com/pocketsizesun/unity-dependency-container
32
31
  licenses: []
33
32
  metadata:
@@ -50,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
49
  - !ruby/object:Gem::Version
51
50
  version: '0'
52
51
  requirements: []
53
- rubygems_version: 3.2.3
52
+ rubygems_version: 3.3.3
54
53
  signing_key:
55
54
  specification_version: 4
56
55
  summary: Unity - Dependencies container utility
Binary file