smart_container 0.3.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.8.0
5
+ class SmartCore::Container::DependencyWatcher::Observer
6
+ # @param container [SmartCore::Container]
7
+ # @param dependency_path [String]
8
+ # @param callback [Proc]
9
+ # @return [void]
10
+ #
11
+ # @api private
12
+ # @since 0.8.0
13
+ def initialize(container, dependency_path, callback)
14
+ @container = container
15
+ @dependency_path = dependency_path
16
+ @callback = callback
17
+ end
18
+
19
+ # @return [void]
20
+ #
21
+ # @api private
22
+ # @since 0.8.0
23
+ def notify!
24
+ callback.call(dependency_path, container)
25
+ end
26
+
27
+ private
28
+
29
+ # @return [SmartCore::Container]
30
+ #
31
+ # @api private
32
+ # @since 0.8.0
33
+ attr_reader :container
34
+
35
+ # @return [String]
36
+ #
37
+ # @api private
38
+ # @since 0.8.0
39
+ attr_reader :dependency_path
40
+
41
+ # @return [Proc]
42
+ #
43
+ # @api private
44
+ # @since 0.8.0
45
+ attr_reader :callback
46
+ end
@@ -12,7 +12,7 @@ module SmartCore::Container::Entities
12
12
  # @since 0.2.0
13
13
  def initialize(dependency_name, dependency_definition)
14
14
  super(dependency_name, dependency_definition)
15
- @lock = SmartCore::Container::ArbitaryLock.new
15
+ @lock = SmartCore::Container::ArbitraryLock.new
16
16
  end
17
17
 
18
18
  # @return [Any]
@@ -18,7 +18,7 @@ class SmartCore::Container::Entities::Namespace < SmartCore::Container::Entities
18
18
  super(namespace_name)
19
19
  @container_klass = Class.new(SmartCore::Container)
20
20
  @container_instance = nil
21
- @lock = SmartCore::Container::ArbitaryLock.new
21
+ @lock = SmartCore::Container::ArbitraryLock.new
22
22
  end
23
23
 
24
24
  # @return [SmartCore::Container]
@@ -57,7 +57,8 @@ class SmartCore::Container
57
57
  #
58
58
  # @api private
59
59
  # @since 0.1.0
60
- def initialize(messegae = nil, path_part:)
60
+ # @version 0.4.0
61
+ def initialize(message = nil, path_part:)
61
62
  @path_part = path_part
62
63
  super(message)
63
64
  end
@@ -11,7 +11,7 @@ module SmartCore::Container::Mixin
11
11
  # @since 0.1.0
12
12
  def included(base_klass)
13
13
  # rubocop:disable Layout/LineLength
14
- base_klass.instance_variable_set(:@__smart_core_container_access_lock__, SmartCore::Container::ArbitaryLock.new)
14
+ base_klass.instance_variable_set(:@__smart_core_container_access_lock__, SmartCore::Container::ArbitraryLock.new)
15
15
  base_klass.instance_variable_set(:@__smart_core_container_klass__, Class.new(SmartCore::Container))
16
16
  base_klass.instance_variable_set(:@__smart_core_container__, nil)
17
17
  # rubocop:enable Layout/LineLength
@@ -34,7 +34,7 @@ module SmartCore::Container::Mixin
34
34
  inherited_container_klass = Class.new(@__smart_core_container_klass__)
35
35
 
36
36
  # rubocop:disable Layout/LineLength
37
- child_klass.instance_variable_set(:@__smart_core_container_access_lock__, SmartCore::Container::ArbitaryLock.new)
37
+ child_klass.instance_variable_set(:@__smart_core_container_access_lock__, SmartCore::Container::ArbitraryLock.new)
38
38
  child_klass.instance_variable_set(:@__smart_core_container_klass__, inherited_container_klass)
39
39
  child_klass.instance_variable_set(:@__smart_core_container__, nil)
40
40
  # rubocop:enable Layout/LineLength
@@ -13,6 +13,18 @@ class SmartCore::Container::Registry
13
13
  # @since 0.3.0
14
14
  DEFAULT_MEMOIZATION_BEHAVIOR = false
15
15
 
16
+ # @return [Boolean]
17
+ #
18
+ # @api private
19
+ # @since 0.4.0
20
+ DEFAULT_ITERATION_YIELD_BEHAVIOUR = false
21
+
22
+ # @return [Boolean]
23
+ #
24
+ # @api private
25
+ # @since 0.4.0
26
+ DEFAULT_KEY_EXTRACTION_BEHAVIOUR = false
27
+
16
28
  # @return [Hash<Symbol,SmartCore::Container::Entity>]
17
29
  #
18
30
  # @api private
@@ -25,7 +37,7 @@ class SmartCore::Container::Registry
25
37
  # @since 0.1.0
26
38
  def initialize
27
39
  @registry = {}
28
- @access_lock = SmartCore::Container::ArbitaryLock.new
40
+ @access_lock = SmartCore::Container::ArbitraryLock.new
29
41
  end
30
42
 
31
43
  # @param entity_path [String, Symbol]
@@ -45,7 +57,7 @@ class SmartCore::Container::Registry
45
57
  # @api private
46
58
  # @since 0.1.0
47
59
  # @version 0.3.0
48
- def register_dependency(name, memoize = DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition)
60
+ def register_dependency(name, memoize: DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition)
49
61
  thread_safe { add_dependency(name, dependency_definition, memoize) }
50
62
  end
51
63
 
@@ -84,6 +96,30 @@ class SmartCore::Container::Registry
84
96
  thread_safe { enumerate(&block) }
85
97
  end
86
98
 
99
+ # @param root_dependency_name [NilClass, String]
100
+ # @option yield_all [Boolean]
101
+ # @param block [Block]
102
+ # @return [Enumerable]
103
+ #
104
+ # @api private
105
+ # @since 0.4.0
106
+ def each_dependency(
107
+ root_dependency_name = nil,
108
+ yield_all: DEFAULT_ITERATION_YIELD_BEHAVIOUR,
109
+ &block
110
+ )
111
+ thread_safe { iterate(root_dependency_name, yield_all: yield_all, &block) }
112
+ end
113
+
114
+ # @option all_variants [Boolean]
115
+ # @return [Array<String>]
116
+ #
117
+ # @api private
118
+ # @since 0.4.0
119
+ def keys(all_variants: DEFAULT_KEY_EXTRACTION_BEHAVIOUR)
120
+ thread_safe { extract_keys(all_variants: all_variants) }
121
+ end
122
+
87
123
  # @return [Hash<String|Symbol,SmartCore::Container::Entities::Base|Any>]
88
124
  #
89
125
  # @api private
@@ -158,9 +194,8 @@ class SmartCore::Container::Registry
158
194
  dependency_name = indifferently_accessable_name(entity_path)
159
195
  registry.fetch(dependency_name)
160
196
  rescue KeyError
161
- raise(SmartCore::Container::ResolvingError.new(<<~MESSAGE, path_part: dependency_name))
162
- Entity with \"#{dependency_name}\" name does not exist
163
- MESSAGE
197
+ error_message = "Entity with \"#{dependency_name}\" name does not exist"
198
+ raise(SmartCore::Container::ResolvingError.new(error_message, path_part: dependency_name))
164
199
  end
165
200
 
166
201
  # @param dependency_name [String, Symbol]
@@ -215,6 +250,58 @@ class SmartCore::Container::Registry
215
250
  namespace_entity.tap { namespace_entity.append_definitions(dependencies_definition) }
216
251
  end
217
252
 
253
+ # @param root_dependency_name [String, NilClass]
254
+ # @param block [Block]
255
+ # @option yield_all [Boolean]
256
+ # @yield [dependency_name, dependency]
257
+ # @yield_param dependency_name [String]
258
+ # @yield_param dependency [Any]
259
+ # @return [Enumerable]
260
+ #
261
+ # @api private
262
+ # @since 0.4.0
263
+ def iterate(root_dependency_name = nil, yield_all: DEFAULT_ITERATION_YIELD_BEHAVIOUR, &block)
264
+ enumerator = Enumerator.new do |yielder|
265
+ registry.each_pair do |dependency_name, dependency|
266
+ final_dependency_name =
267
+ if root_dependency_name
268
+ "#{root_dependency_name}" \
269
+ "#{SmartCore::Container::DependencyResolver::PATH_PART_SEPARATOR}" \
270
+ "#{dependency_name}"
271
+ else
272
+ dependency_name
273
+ end
274
+
275
+ case dependency
276
+ when SmartCore::Container::Entities::Dependency
277
+ yielder.yield(final_dependency_name, dependency.reveal)
278
+ when SmartCore::Container::Entities::Namespace
279
+ yielder.yield(final_dependency_name, dependency.reveal) if yield_all
280
+ dependency.reveal.registry.each_dependency(
281
+ final_dependency_name,
282
+ yield_all: yield_all,
283
+ &block
284
+ )
285
+ end
286
+ end
287
+ end
288
+
289
+ block_given? ? enumerator.each(&block) : enumerator.each
290
+ end
291
+
292
+ # @option all_variants [Boolean]
293
+ # @return [Array<String>]
294
+ #
295
+ # @api private
296
+ # @since 0.4.0
297
+ def extract_keys(all_variants: DEFAULT_KEY_EXTRACTION_BEHAVIOUR)
298
+ Set.new.tap do |dependency_names|
299
+ iterate(yield_all: all_variants) do |dependency_name, _dependency|
300
+ dependency_names << dependency_name
301
+ end
302
+ end.to_a
303
+ end
304
+
218
305
  # @param name [String, Symbol]
219
306
  # @return [void]
220
307
  #
@@ -4,7 +4,7 @@ module SmartCore
4
4
  class Container
5
5
  # @api public
6
6
  # @since 0.1.0
7
- # @version 0.3.0
8
- VERSION = '0.3.0'
7
+ # @version 0.8.0
8
+ VERSION = '0.8.0'
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@
3
3
  require_relative 'lib/smart_core/container/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.9')
6
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.10')
7
7
 
8
8
  spec.name = 'smart_container'
9
9
  spec.version = SmartCore::Container::VERSION
@@ -27,12 +27,12 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'smart_engine', '~> 0.2'
30
+ spec.add_dependency 'smart_engine', '~> 0.5'
31
31
 
32
32
  spec.add_development_dependency 'bundler', '~> 2.1'
33
33
  spec.add_development_dependency 'rake', '~> 13.0'
34
34
  spec.add_development_dependency 'rspec', '~> 3.9'
35
- spec.add_development_dependency 'armitage-rubocop', '~> 0.78'
36
- spec.add_development_dependency 'simplecov', '~> 0.17'
37
- spec.add_development_dependency 'pry', '~> 0.12'
35
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.81'
36
+ spec.add_development_dependency 'simplecov', '~> 0.18'
37
+ spec.add_development_dependency 'pry', '~> 0.13'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.5'
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.2'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.78'
75
+ version: '0.81'
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: '0.78'
82
+ version: '0.81'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.17'
89
+ version: '0.18'
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.17'
96
+ version: '0.18'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.12'
103
+ version: '0.13'
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.12'
110
+ version: '0.13'
111
111
  description: Thread-safe semanticaly-defined IoC/DI Container
112
112
  email:
113
113
  - iamdaiver@gmail.com
@@ -129,7 +129,7 @@ files:
129
129
  - bin/console
130
130
  - bin/setup
131
131
  - lib/smart_core/container.rb
132
- - lib/smart_core/container/arbitary_lock.rb
132
+ - lib/smart_core/container/arbitrary_lock.rb
133
133
  - lib/smart_core/container/definition_dsl.rb
134
134
  - lib/smart_core/container/definition_dsl/command_set.rb
135
135
  - lib/smart_core/container/definition_dsl/commands.rb
@@ -149,6 +149,8 @@ files:
149
149
  - lib/smart_core/container/dependency_resolver.rb
150
150
  - lib/smart_core/container/dependency_resolver/route.rb
151
151
  - lib/smart_core/container/dependency_resolver/route/cursor.rb
152
+ - lib/smart_core/container/dependency_watcher.rb
153
+ - lib/smart_core/container/dependency_watcher/observer.rb
152
154
  - lib/smart_core/container/entities.rb
153
155
  - lib/smart_core/container/entities/base.rb
154
156
  - lib/smart_core/container/entities/dependency.rb
@@ -178,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
180
  requirements:
179
181
  - - ">="
180
182
  - !ruby/object:Gem::Version
181
- version: 2.4.9
183
+ version: 2.4.10
182
184
  required_rubygems_version: !ruby/object:Gem::Requirement
183
185
  requirements:
184
186
  - - ">="