smart_injection 0.0.0.alpha → 0.2.0

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: 8648636507a04e403ca6e55d0371d3191d248e09e63f9c977128847fc382b00f
4
- data.tar.gz: 218f815047bf27cd213743ee0db5c82f7676beff59ccc95f0de5dad656a0e028
3
+ metadata.gz: be2ddc375b6609c3bfa9ffebf1b7b85ddccdaa60018e563feeb10ae5693c637e
4
+ data.tar.gz: 3ca99d637fed907c2a2241d01a704eea1eb9d538ce61b29d741925b62d75bef1
5
5
  SHA512:
6
- metadata.gz: 8343d93be3d7fe20c1996255a8927d520e8a23a2f024d1af73b40346ddc59add22d4b09aa3b33a8afc744ce60638a68ea98c6beb249f5fdbec254243626b561e
7
- data.tar.gz: 256144d63e96bf91f2a2b60fd966935a4012c41cf509aa03159dac102c4eb9bc688fb207ec92f99928cb2e695ed5305a9e1601f7f3b0bfb1c386302baa319656
6
+ metadata.gz: bf831df6f117f75c3ff7eca97ebe7467bc87b4b4464851d2a489f71ac959f59fa101fba123cd194a10501f43617ebfee73d68643bd3968049ba0942cbfa1c269
7
+ data.tar.gz: 465ab0c6f1849d045776c9e88e448872fbf5785641286a94205a9a770d4f56518206f473b9f0d1c29109648f90ebc4206c5ba4ed85cfefea2619dcceaa824da8
@@ -5,7 +5,8 @@ inherit_gem:
5
5
  - lib/rubocop.rspec.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.7.1
8
+ TargetRubyVersion: 3.0.0
9
+ NewCops: enable
9
10
  Include:
10
11
  - lib/**/*.rb
11
12
  - spec/**/*.rb
@@ -1,2 +1,13 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
+
4
+ # [0.2.0] - 2021-01-18
5
+ ## Added
6
+ - Support for *Ruby@3*;
7
+
8
+ ## Changed
9
+ - No more `TravisCI` (todo: migrate to `GitHub Actions`);
10
+
11
+ # [0.1.0] - 2020-07-09
12
+
13
+ - Release :)
@@ -1,104 +1,107 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_injection (0.0.0.alpha)
5
- smart_container (~> 0.7)
6
- smart_engine (~> 0.7)
4
+ smart_injection (0.2.0)
5
+ smart_container (~> 0.9)
6
+ smart_engine (~> 0.11)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.0.3.2)
11
+ activesupport (6.1.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- armitage-rubocop (0.85.1)
18
- rubocop (= 0.85.1)
19
- rubocop-performance (= 1.6.1)
20
- rubocop-rails (= 2.6.0)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ armitage-rubocop (1.7.0.1)
18
+ rubocop (= 1.7.0)
19
+ rubocop-performance (= 1.9.1)
20
+ rubocop-rails (= 2.9.1)
21
21
  rubocop-rake (= 0.5.1)
22
- rubocop-rspec (= 1.40.0)
22
+ rubocop-rspec (= 2.1.0)
23
23
  ast (2.4.1)
24
24
  coderay (1.1.3)
25
- concurrent-ruby (1.1.6)
25
+ concurrent-ruby (1.1.7)
26
26
  diff-lcs (1.4.4)
27
- docile (1.3.2)
28
- i18n (1.8.3)
27
+ docile (1.3.5)
28
+ i18n (1.8.7)
29
29
  concurrent-ruby (~> 1.0)
30
30
  method_source (1.0.0)
31
- minitest (5.14.1)
32
- parallel (1.19.2)
33
- parser (2.7.1.4)
31
+ minitest (5.14.3)
32
+ parallel (1.20.1)
33
+ parser (3.0.0.0)
34
34
  ast (~> 2.4.1)
35
35
  pry (0.13.1)
36
36
  coderay (~> 1.1)
37
37
  method_source (~> 1.0)
38
38
  rack (2.2.3)
39
39
  rainbow (3.0.0)
40
- rake (13.0.1)
41
- regexp_parser (1.7.1)
40
+ rake (13.0.3)
41
+ regexp_parser (2.0.3)
42
42
  rexml (3.2.4)
43
- rspec (3.9.0)
44
- rspec-core (~> 3.9.0)
45
- rspec-expectations (~> 3.9.0)
46
- rspec-mocks (~> 3.9.0)
47
- rspec-core (3.9.2)
48
- rspec-support (~> 3.9.3)
49
- rspec-expectations (3.9.2)
43
+ rspec (3.10.0)
44
+ rspec-core (~> 3.10.0)
45
+ rspec-expectations (~> 3.10.0)
46
+ rspec-mocks (~> 3.10.0)
47
+ rspec-core (3.10.1)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-expectations (3.10.1)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-mocks (3.9.1)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-mocks (3.10.1)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.9.0)
55
- rspec-support (3.9.3)
56
- rubocop (0.85.1)
54
+ rspec-support (~> 3.10.0)
55
+ rspec-support (3.10.1)
56
+ rubocop (1.7.0)
57
57
  parallel (~> 1.10)
58
- parser (>= 2.7.0.1)
58
+ parser (>= 2.7.1.5)
59
59
  rainbow (>= 2.2.2, < 4.0)
60
- regexp_parser (>= 1.7)
60
+ regexp_parser (>= 1.8, < 3.0)
61
61
  rexml
62
- rubocop-ast (>= 0.0.3)
62
+ rubocop-ast (>= 1.2.0, < 2.0)
63
63
  ruby-progressbar (~> 1.7)
64
64
  unicode-display_width (>= 1.4.0, < 2.0)
65
- rubocop-ast (0.1.0)
66
- parser (>= 2.7.0.1)
67
- rubocop-performance (1.6.1)
68
- rubocop (>= 0.71.0)
69
- rubocop-rails (2.6.0)
65
+ rubocop-ast (1.4.0)
66
+ parser (>= 2.7.1.5)
67
+ rubocop-performance (1.9.1)
68
+ rubocop (>= 0.90.0, < 2.0)
69
+ rubocop-ast (>= 0.4.0)
70
+ rubocop-rails (2.9.1)
70
71
  activesupport (>= 4.2.0)
71
72
  rack (>= 1.1)
72
- rubocop (>= 0.82.0)
73
+ rubocop (>= 0.90.0, < 2.0)
73
74
  rubocop-rake (0.5.1)
74
75
  rubocop
75
- rubocop-rspec (1.40.0)
76
- rubocop (>= 0.68.1)
77
- ruby-progressbar (1.10.1)
78
- simplecov (0.18.5)
76
+ rubocop-rspec (2.1.0)
77
+ rubocop (~> 1.0)
78
+ rubocop-ast (>= 1.1.0)
79
+ ruby-progressbar (1.11.0)
80
+ simplecov (0.21.2)
79
81
  docile (~> 1.1)
80
82
  simplecov-html (~> 0.11)
81
- simplecov-html (0.12.2)
82
- smart_container (0.7.0)
83
- smart_engine (~> 0.5)
84
- smart_engine (0.7.0)
85
- thread_safe (0.3.6)
86
- tzinfo (1.2.7)
87
- thread_safe (~> 0.1)
83
+ simplecov_json_formatter (~> 0.1)
84
+ simplecov-html (0.12.3)
85
+ simplecov_json_formatter (0.1.2)
86
+ smart_container (0.9.0)
87
+ smart_engine (~> 0.11)
88
+ smart_engine (0.11.0)
89
+ tzinfo (2.0.4)
90
+ concurrent-ruby (~> 1.0)
88
91
  unicode-display_width (1.7.0)
89
- zeitwerk (2.3.1)
92
+ zeitwerk (2.4.2)
90
93
 
91
94
  PLATFORMS
92
- ruby
95
+ x86_64-darwin-20
93
96
 
94
97
  DEPENDENCIES
95
- armitage-rubocop (~> 0.85)
96
- bundler (~> 2.1)
98
+ armitage-rubocop (~> 1.7)
99
+ bundler (~> 2.2)
97
100
  pry (~> 0.13)
98
101
  rake (~> 13.0)
99
- rspec (~> 3.9)
100
- simplecov (~> 0.18)
102
+ rspec (~> 3.10)
103
+ simplecov (~> 0.21)
101
104
  smart_injection!
102
105
 
103
106
  BUNDLED WITH
104
- 2.1.4
107
+ 2.2.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # SmartCore::Injection &middot; [![Gem Version](https://badge.fury.io/rb/smart_injection.svg)](https://badge.fury.io/rb/smart_injection) [![Build Status](https://travis-ci.org/smart-rb/smart_injection.svg?branch=master)](https://travis-ci.org/smart-rb/smart_injection)
1
+ # SmartCore::Injection &middot; [![Gem Version](https://badge.fury.io/rb/smart_injection.svg)](https://badge.fury.io/rb/smart_injection)
2
2
 
3
- Dependency injection principles and idioms realized in scope of Ruby.
3
+ Dependency injection principles and idioms realized in scope of Ruby. Support for method-injeciton strategy, container-based dependency resolving, static and dynamic bindings and etc.
4
4
 
5
5
  ---
6
6
 
@@ -8,7 +8,7 @@ Dependency injection principles and idioms realized in scope of Ruby.
8
8
 
9
9
  - `method-injection` strategy
10
10
  - `soon:` constructor injection strategy;
11
- - `soon:` attribute injection strategy;
11
+ - `soon:` property injection strategy;
12
12
  - realized as a mixin;
13
13
  - instance-method dependency injection;
14
14
  - class-method dependency injection;
@@ -22,6 +22,18 @@ Dependency injection principles and idioms realized in scope of Ruby.
22
22
 
23
23
  ---
24
24
 
25
+ ## Usage
26
+
27
+ - [Installation](#installation)
28
+ - [Synopsis](#synopsis)
29
+ - [Roadmap](#roadmap)
30
+ - [Build](#build)
31
+ - [Contributing](#contributing)
32
+ - [License](#license)
33
+ - [Authors](#authors)
34
+
35
+ ---
36
+
25
37
  ## Installation
26
38
 
27
39
  ```ruby
@@ -80,18 +92,18 @@ class MiniService
80
92
  include SmartCore::Injection(AppContainer, ServiceContainer)
81
93
 
82
94
  # --- or ---
83
- include SmartCore::Container
95
+ include SmartCore::Injection
84
96
  register_container(AppContainer, ServiceContainer)
85
97
 
86
98
  # import dependencies to an instance
87
- import { db: 'data_storage.main' }, bind: :dynamic, access: :private
88
- import { rnd: 'rands.alphanum' }, bind: :static, memoize: true
99
+ import({ db: 'data_storage.main' }, bind: :dynamic, access: :private)
100
+ import({ rnd: 'rands.alphanum' }, bind: :static, memoize: true)
89
101
 
90
102
  # import dependencies to a class
91
- import_static { cache: 'data_storage.cache', hexer: 'rands.hex' }, bind: :static
103
+ import_static({ cache: 'data_storage.cache', hexer: 'rands.hex' }, bind: :static)
92
104
 
93
105
  # import from a non-registered container
94
- import { phone_client: 'phone_clients.nexmo' }, from: GlobalContainer
106
+ import({ phone_client: 'phone_clients.nexmo' }, from: GlobalContainer)
95
107
 
96
108
  def call
97
109
  db # => returns data_storage.main
@@ -105,6 +117,36 @@ end
105
117
 
106
118
  ---
107
119
 
120
+ ## Roadmap
121
+
122
+ - **[0.3.0]** - support for default injection configuration which should be specified in `SmartCore::Injection` module inclusion (in addition to default containers)
123
+ - **[0.x.0]** - more docs, more examples, more tips-and-tricks :)
124
+ - **[0.x.0]** - migrate to GithubActions;
125
+
126
+ ---
127
+
128
+ ## Build
129
+
130
+ - run tests:
131
+
132
+ ```shell
133
+ bundle exce rake rspec
134
+ ```
135
+
136
+ - run code style checking:
137
+
138
+ ```shell
139
+ bundle exec rake rubocop
140
+ ```
141
+
142
+ - run code style checking with auto-correction:
143
+
144
+ ```shell
145
+ bundle exec rake rubocop -A
146
+ ```
147
+
148
+ ---
149
+
108
150
  ## Contributing
109
151
 
110
152
  - Fork it ( https://github.com/smart-rb/smart_injection )
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'smart_core/injection'
5
+ require 'smart_core'
6
6
 
7
- require 'irb'
8
- IRB.start(__FILE__)
7
+ require 'pry'
8
+ Pry.start
@@ -25,6 +25,7 @@ module SmartCore
25
25
  # @since 0.1.0
26
26
  module Injection
27
27
  require_relative 'injection/version'
28
+ require_relative 'injection/errors'
28
29
  require_relative 'injection/injector'
29
30
  require_relative 'injection/locator'
30
31
  require_relative 'injection/dsl'
@@ -14,7 +14,27 @@ module SmartCore::Injection::DSL
14
14
  :@__smart_injection_injector__,
15
15
  SmartCore::Injection::Injector.new(base_klass)
16
16
  )
17
+
17
18
  base_klass.extend(ClassMethods)
19
+ base_klass.singleton_class.prepend(ClassInheritance)
20
+ end
21
+ end
22
+
23
+ # @api private
24
+ # @since 0.1.0
25
+ module ClassInheritance
26
+ # @param child_klass [Class]
27
+ # @return [void]
28
+ #
29
+ # @api private
30
+ # @since 0.1.0
31
+ def inherited(child_klass)
32
+ child_klass.instance_variable_set(
33
+ :@__smart_injection_injector__,
34
+ __smart_injection_injector__.duplicate_for(child_klass)
35
+ )
36
+ child_klass.singleton_class.prepend(ClassInheritance)
37
+ super
18
38
  end
19
39
  end
20
40
 
@@ -65,7 +85,7 @@ module SmartCore::Injection::DSL
65
85
  # @api public
66
86
  # @since 0.1.0
67
87
  def register_container(*containers)
68
- __smart_injection_injector__.register_container(containers)
88
+ __smart_injection_injector__.register_container(*containers)
69
89
  end
70
90
 
71
91
  # @return [Array<SmartCore::Container>]
@@ -76,12 +96,12 @@ module SmartCore::Injection::DSL
76
96
  __smart_injection_injector__.associated_containers
77
97
  end
78
98
 
79
- private
80
-
81
99
  # @return [SmartCore::Injection::Injector]
82
100
  #
83
101
  # @api private
84
102
  # @since 0.1.0
85
- attr_reader :__smart_injection_injector__
103
+ def __smart_injection_injector__
104
+ @__smart_injection_injector__
105
+ end
86
106
  end
87
107
  end
@@ -8,4 +8,8 @@ module SmartCore::Injection
8
8
  # @api public
9
9
  # @since 0.1.0
10
10
  ArgumentError = Class.new(SmartCore::ArgumentError)
11
+
12
+ # @api public
13
+ # @since 0.1.0
14
+ NoRegisteredContainersError = Class.new(Error)
11
15
  end
@@ -50,7 +50,7 @@ class SmartCore::Injection::Injector
50
50
  #
51
51
  # @api private
52
52
  # @since 0.1.0
53
- def register_container(containers)
53
+ def register_container(*containers)
54
54
  thread_safe { link_container(containers) }
55
55
  end
56
56
 
@@ -62,6 +62,15 @@ class SmartCore::Injection::Injector
62
62
  thread_safe { linked_containers.list }
63
63
  end
64
64
 
65
+ # @param another_injectable [Class, Module]
66
+ # @return [SmartCore::Injection::Injector]
67
+ #
68
+ # @api private
69
+ # @since 0.1.0
70
+ def duplicate_for(another_injectable)
71
+ thread_safe { create_duplicate(another_injectable) }
72
+ end
73
+
65
74
  private
66
75
 
67
76
  # @return [Class, Module]
@@ -76,6 +85,19 @@ class SmartCore::Injection::Injector
76
85
  # @since 0.1.0
77
86
  attr_reader :linked_containers
78
87
 
88
+ # @param another_injectable [Class, Module]
89
+ # @return [SmartCore::Injection::Injector]
90
+ #
91
+ # @api private
92
+ # @since 0.1.0
93
+ def create_duplicate(another_injectable)
94
+ self.class.new(another_injectable).tap do |duplicate|
95
+ linked_containers.each do |container|
96
+ duplicate.register_container(container)
97
+ end
98
+ end
99
+ end
100
+
79
101
  # @param imports [Hash<String|Symbol,String>]
80
102
  # @param memoize [Boolean]
81
103
  # @param access [Symbol]
@@ -3,6 +3,8 @@
3
3
  # @api private
4
4
  # @since 0.1.0
5
5
  class SmartCore::Injection::Injector::ContainerSet
6
+ require_relative 'container_set/adding_listener'
7
+
6
8
  # @since 0.1.0
7
9
  include Enumerable
8
10
 
@@ -12,6 +14,7 @@ class SmartCore::Injection::Injector::ContainerSet
12
14
  # @since 0.1.0
13
15
  def initialize
14
16
  @containers = [] # NOTE: we use Array cuz we need an ordered set
17
+ @adding_listeners = []
15
18
  @access_lock = SmartCore::Engine::Lock.new
16
19
  end
17
20
 
@@ -25,6 +28,17 @@ class SmartCore::Injection::Injector::ContainerSet
25
28
  end
26
29
  alias_method :<<, :add
27
30
 
31
+ # @param listener [Block]
32
+ # @yield [container]
33
+ # @yieldparam container [SmartCore::Container]
34
+ # @return [void]
35
+ #
36
+ # @api private
37
+ # @since 0.1.0
38
+ def listen_addings(&listener)
39
+ thread_safe { add_adding_listener(listener) }
40
+ end
41
+
28
42
  # @param block [Block]
29
43
  # @yield [container]
30
44
  # @yieldparam container [SmartCore::Container]
@@ -63,6 +77,18 @@ class SmartCore::Injection::Injector::ContainerSet
63
77
  # @since 0.1.0
64
78
  attr_reader :containers
65
79
 
80
+ # @return [Array<SmartCore::Injection::Injector::ContainerSet::AddingListener>]
81
+ attr_reader :adding_listeners
82
+
83
+ # @param listener [Proc]
84
+ # @return [void]
85
+ #
86
+ # @api private
87
+ # @since 0.1.0
88
+ def add_adding_listener(listener)
89
+ adding_listeners << SmartCore::Injection::Injector::ContainerSet::AddingListener.new(listener)
90
+ end
91
+
66
92
  # @param container [SmartCore::Container]
67
93
  # @return [void]
68
94
  #
@@ -73,6 +99,7 @@ class SmartCore::Injection::Injector::ContainerSet
73
99
  # - #concant is used to prevent container duplications in ordered set;
74
100
  # - @containers should have an ordered unified container list;
75
101
  containers.concat([container])
102
+ adding_listeners.each { |listener| listener.notify(container) }
76
103
  end
77
104
 
78
105
  # @param block [Block]
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.1.0
5
+ class SmartCore::Injection::Injector::ContainerSet::AddingListener
6
+ # @param listener [Proc]
7
+ # @return [void]
8
+ #
9
+ # @api private
10
+ # @since 0.1.0
11
+ def initialize(listener)
12
+ @listener = listener
13
+ end
14
+
15
+ # @param cotnainer [SmartCore::Container]
16
+ #
17
+ # @api private
18
+ # @since 0.1.0
19
+ def notify(container)
20
+ listener.call(container)
21
+ end
22
+
23
+ private
24
+
25
+ # @return [Proc]
26
+ #
27
+ # @api private
28
+ # @since 0.1.0
29
+ attr_reader :listener
30
+ end
@@ -39,7 +39,7 @@ class SmartCore::Injection::Locator
39
39
  # @api private
40
40
  # @since 0.1.0
41
41
  def rebind_dependency
42
- dependency.rebind { container_proxy.resolve(import_path) }
42
+ dependency.rebind { container_proxy.resolve_dependency(import_path) }
43
43
  end
44
44
  alias_method :rebind!, :rebind_dependency
45
45
 
@@ -12,11 +12,14 @@ class SmartCore::Injection::Locator::ContainerProxy
12
12
  def initialize(registered_containers, explicitly_passed_container)
13
13
  @registered_containers = registered_containers
14
14
  @explicitly_passed_container = explicitly_passed_container
15
+ @observers = Hash.new { |h, k| h[k] = [] }
16
+ registered_containers.listen_addings { |container| listen_changes(container) }
15
17
  end
16
18
 
17
19
  # @param dependency_path [String]
18
20
  # @return [Any]
19
21
  #
22
+ # @raise [SmartCore::Injection::NoRegisteredContainersError]
20
23
  # @raise [SmartCore::Container::ResolvingError]
21
24
  #
22
25
  # @api private
@@ -32,7 +35,13 @@ class SmartCore::Injection::Locator::ContainerProxy
32
35
  end
33
36
  end
34
37
 
35
- raise(resolving_error)
38
+ unless resolving_error
39
+ raise(SmartCore::Injection::NoRegisteredContainersError, <<~ERROR_MESSAGE)
40
+ You haven't registered any containers for import.
41
+ ERROR_MESSAGE
42
+ else
43
+ raise(resolving_error)
44
+ end
36
45
  end
37
46
 
38
47
  # @param import_path [String]
@@ -42,11 +51,21 @@ class SmartCore::Injection::Locator::ContainerProxy
42
51
  # @api private
43
52
  # @since 0.1.0
44
53
  def observe(import_path, &observer)
45
- # TODO: implement
54
+ register_observer(import_path, observer)
55
+
56
+ each_container do |container|
57
+ container.observe(import_path) { |path, cntr| process_changement(cntr, path) }
58
+ end
46
59
  end
47
60
 
48
61
  private
49
62
 
63
+ # @return [Hash<String,Proc>]
64
+ #
65
+ # @api private
66
+ # @since 0.1.0
67
+ attr_reader :observers
68
+
50
69
  # @return [SmartCore::Injection::Injector::ContainerSet]
51
70
  #
52
71
  # @api private
@@ -59,15 +78,65 @@ class SmartCore::Injection::Locator::ContainerProxy
59
78
  # @since 0.1.0
60
79
  attr_reader :explicitly_passed_container
61
80
 
81
+ # @param import_path [NilClass, String]
82
+ # @param container [SmartCore::Container]
83
+ # @return [void]
84
+ #
85
+ # @api private
86
+ # @since 0.1.0
87
+ def process_changement(container, import_path = nil)
88
+ observed_pathes = import_path ? [import_path] : observed_import_pathes
89
+
90
+ observed_pathes.each do |observed_path|
91
+ suitable_container = each_container.find { |cntr| cntr.key?(observed_path) }
92
+ break unless suitable_container
93
+ notify_observers(observed_path) if suitable_container == container
94
+ end
95
+ end
96
+
97
+ # @param import_path [String]
98
+ # @param observer [SmartCore::Container]
99
+ # @return [void]
100
+ #
101
+ # @api private
102
+ # @since 0.1.0
103
+ def register_observer(import_path, observer)
104
+ observers[import_path] << observer
105
+ end
106
+
107
+ # @return [Array<String>]
108
+ #
109
+ # @api private
110
+ # @since 0.1.0
111
+ def observed_import_pathes
112
+ observers.keys
113
+ end
114
+
115
+ # @param import_pathes [String]
116
+ # @return [void]
117
+ #
118
+ # @api private
119
+ # @since 0.1.0
120
+ def notify_observers(*import_pathes)
121
+ import_pathes.each { |import_path| observers.fetch(import_path).each(&:call) }
122
+ end
123
+
62
124
  # @param block [Block]
63
125
  # @yield [container]
64
126
  # @yieldparam container [SmartCore::Container]
65
- # @return [void]
127
+ # @return [Enumerable]
66
128
  #
67
129
  # @api private
68
130
  # @since 0.1.0
69
131
  def each_container(&block)
70
- yield(explicitly_passed_container) if explicitly_passed_container
71
- registered_containers.reverse_each(&block)
132
+ enumerator = Enumerator.new do |yielder|
133
+ if explicitly_passed_container
134
+ yielder.yield(explicitly_passed_container)
135
+ else
136
+ registered_containers.reverse_each(&yielder)
137
+ end
138
+ end
139
+
140
+ block_given? ? enumerator.each(&block) : enumerator.each
72
141
  end
73
142
  end
@@ -20,7 +20,7 @@ class SmartCore::Injection::Locator::Dependency
20
20
  # @since 0.1.0
21
21
  def rebind(&block)
22
22
  with_barrier do
23
- @bind = false
23
+ @binded = false
24
24
  bind(&block)
25
25
  end
26
26
  end
@@ -36,7 +36,7 @@ class SmartCore::Injection::Locator::Dependency
36
36
  @value
37
37
  else
38
38
  @binded = true
39
- @value = yield(@value)
39
+ @value = yield
40
40
  end
41
41
  end
42
42
  end
@@ -11,8 +11,8 @@ module SmartCore::Injection::Locator::Factory
11
11
  # @since 0.1.0
12
12
  def create(injection_settings, import_key, import_path)
13
13
  container_proxy = create_container_proxy(injection_settings)
14
- locator = create_locator(import_path, container_proxy).tap do
15
- control_inection_memoization(injection_settings, container_proxy, locator, import_path)
14
+ create_locator(import_path, container_proxy).tap do |locator|
15
+ control_injection_memoization(injection_settings, container_proxy, locator, import_path)
16
16
  end
17
17
  end
18
18
 
@@ -46,8 +46,10 @@ module SmartCore::Injection::Locator::Factory
46
46
  #
47
47
  # @api private
48
48
  # @since 0.1.0
49
- def control_inection_memoization(injection_settings, container_proxy, locator, import_path)
50
- container_proxy.observe(import_path) { locator.rebind! } unless injection_settings.memoize
49
+ def control_injection_memoization(injection_settings, container_proxy, locator, import_path)
50
+ container_proxy.observe(import_path) do
51
+ locator.rebind!
52
+ end unless injection_settings.memoize
51
53
  end
52
54
  end
53
55
  end
@@ -6,6 +6,7 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- VERSION = '0.0.0.alpha'
9
+ # @version 0.2.0
10
+ VERSION = '0.2.0'
10
11
  end
11
12
  end
@@ -11,7 +11,11 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['iamdaiver@gmail.com']
12
12
 
13
13
  spec.summary = 'DI principles and idioms realized in scope of Ruby'
14
- spec.description = 'DI principles and idioms realized in scope of Ruby'
14
+ spec.description = 'DI principles and idioms realized in scope of Ruby.' \
15
+ 'Support for method-injeciton strategy, ' \
16
+ 'container-based dependency resolving, ' \
17
+ 'static and dynamic bindings and etc.'
18
+
15
19
  spec.homepage = 'https://github.com/smart-rb/smart_injection'
16
20
  spec.license = 'MIT'
17
21
 
@@ -30,13 +34,13 @@ Gem::Specification.new do |spec|
30
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
35
  spec.require_paths = ['lib']
32
36
 
33
- spec.add_runtime_dependency 'smart_engine', '~> 0.7'
34
- spec.add_runtime_dependency 'smart_container', '~> 0.7'
37
+ spec.add_runtime_dependency 'smart_engine', '~> 0.11'
38
+ spec.add_runtime_dependency 'smart_container', '~> 0.9'
35
39
 
36
- spec.add_development_dependency 'bundler', '~> 2.1'
40
+ spec.add_development_dependency 'bundler', '~> 2.2'
37
41
  spec.add_development_dependency 'rake', '~> 13.0'
38
- spec.add_development_dependency 'rspec', '~> 3.9'
39
- spec.add_development_dependency 'armitage-rubocop', '~> 0.85'
40
- spec.add_development_dependency 'simplecov', '~> 0.18'
42
+ spec.add_development_dependency 'rspec', '~> 3.10'
43
+ spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
44
+ spec.add_development_dependency 'simplecov', '~> 0.21'
41
45
  spec.add_development_dependency 'pry', '~> 0.13'
42
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_injection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.alpha
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.7'
19
+ version: '0.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.7'
26
+ version: '0.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: smart_container
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.7'
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.1'
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.1'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.9'
75
+ version: '3.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.9'
82
+ version: '3.10'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: armitage-rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.85'
89
+ version: '1.7'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.85'
96
+ version: '1.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.18'
103
+ version: '0.21'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.18'
110
+ version: '0.21'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +122,9 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.13'
125
- description: DI principles and idioms realized in scope of Ruby
125
+ description: DI principles and idioms realized in scope of Ruby.Support for method-injeciton
126
+ strategy, container-based dependency resolving, static and dynamic bindings and
127
+ etc.
126
128
  email:
127
129
  - iamdaiver@gmail.com
128
130
  executables: []
@@ -132,7 +134,6 @@ files:
132
134
  - ".gitignore"
133
135
  - ".rspec"
134
136
  - ".rubocop.yml"
135
- - ".travis.yml"
136
137
  - CHANGELOG.md
137
138
  - CODE_OF_CONDUCT.md
138
139
  - Gemfile
@@ -147,6 +148,7 @@ files:
147
148
  - lib/smart_core/injection/errors.rb
148
149
  - lib/smart_core/injection/injector.rb
149
150
  - lib/smart_core/injection/injector/container_set.rb
151
+ - lib/smart_core/injection/injector/container_set/adding_listener.rb
150
152
  - lib/smart_core/injection/injector/injection_settings.rb
151
153
  - lib/smart_core/injection/injector/injection_settings/incompatability_control.rb
152
154
  - lib/smart_core/injection/injector/modulizer.rb
@@ -165,7 +167,7 @@ metadata:
165
167
  homepage_uri: https://github.com/smart-rb/smart_injection
166
168
  source_code_uri: https://github.com/smart-rb/smart_injection
167
169
  changelog_uri: https://github.com/smart-rb/smart_injection/blob/master/CHANGELOG.md
168
- post_install_message:
170
+ post_install_message:
169
171
  rdoc_options: []
170
172
  require_paths:
171
173
  - lib
@@ -176,12 +178,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
178
  version: 2.4.10
177
179
  required_rubygems_version: !ruby/object:Gem::Requirement
178
180
  requirements:
179
- - - ">"
181
+ - - ">="
180
182
  - !ruby/object:Gem::Version
181
- version: 1.3.1
183
+ version: '0'
182
184
  requirements: []
183
- rubygems_version: 3.1.2
184
- signing_key:
185
+ rubygems_version: 3.2.3
186
+ signing_key:
185
187
  specification_version: 4
186
188
  summary: DI principles and idioms realized in scope of Ruby
187
189
  test_files: []
@@ -1,23 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- os: linux
5
- dist: xenial
6
- jobs:
7
- fast_finish: true
8
- include:
9
- - rvm: 2.4.10
10
- - rvm: 2.5.8
11
- - rvm: 2.6.6
12
- - rvm: 2.7.1
13
- - rvm: jruby-head
14
- - rvm: ruby-head
15
- - rvm: truffleruby
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
19
- - rvm: truffleruby
20
- before_install: gem install bundler
21
- script:
22
- - bundle exec rake rubocop
23
- - bundle exec rake rspec