smart_container 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -15
- data/Gemfile.lock +1 -1
- data/README.md +6 -6
- data/lib/smart_core/container/definition_dsl.rb +6 -2
- data/lib/smart_core/container/registry.rb +8 -2
- data/lib/smart_core/container/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 919cbfa847aa6931a64cf70c07269a0883ac0b5f47e9b84243854b0ea626f49e
|
4
|
+
data.tar.gz: b9fcfbf5060a973bf1aa8e81d8a78cbdabf243e585dea583e64904e698c094dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 282c7f32da7c8029518b72f94b1047ed71046db44b0e18c9eef2557158bbf3ad97bb5ed658af9a836105964175fa2fd5a5b6ddb0568700b39ed471e7b6ec4c28
|
7
|
+
data.tar.gz: bfabb455faa37954f0700d2f910e6de93ed4194bb9bb63d45918af7e81de92a5f07f3edf503c922a363d682d6a227cad64a5e5f4c53b355db0b8018757397bb4
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [0.
|
4
|
+
## [0.3.0] - 2020-01-05
|
5
|
+
### Changed
|
6
|
+
- Dependency resolving is not memoized by default (previously: totally memoized 😱);
|
7
|
+
|
8
|
+
## [0.2.0] - 2020-01-05
|
5
9
|
### Changed
|
6
10
|
- (Private API (`SmartCore::Container::RegistryBuilder`)) improved semantics:
|
7
11
|
- `build_state` is renamed to `initialise`;
|
8
12
|
- `build_definitions` is renamed to `define`;
|
9
|
-
- (Public API) Support for memoized dependencies (all dependencies are memoized by default)
|
10
|
-
```ruby
|
11
|
-
class MyContainer < SmartCore::Container
|
12
|
-
namespace(:some_naespace) do
|
13
|
-
# memoized by default
|
14
|
-
register(:random_number) { rand(1000) }
|
15
|
-
# explicit memoization
|
16
|
-
register(:random_number, memoized: true) { rand(1000) }
|
17
|
-
|
18
|
-
# register non-memoizable dependency
|
19
|
-
register(:random_number, memoized: false) { rand(1000) }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
```
|
13
|
+
- (Public API) Support for memoized dependencies (all dependencies are memoized by default);
|
23
14
|
|
24
15
|
## [0.1.0] - 2020-01-02
|
25
16
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,19 +27,19 @@ require 'smart_core/container'
|
|
27
27
|
```ruby
|
28
28
|
class Container < SmartCore::Container
|
29
29
|
namespace(:database) do # support for namespaces
|
30
|
-
register(:resolver) { SomeDatabaseResolver.new } # dependency registration
|
30
|
+
register(:resolver, memoize: true) { SomeDatabaseResolver.new } # dependency registration
|
31
31
|
|
32
32
|
namespace(:cache) do # support for nested naespaces
|
33
|
-
register(:memcached) { MemcachedClient.new }
|
34
|
-
register(:redis) { RedisClient.new }
|
33
|
+
register(:memcached, memoize: true) { MemcachedClient.new }
|
34
|
+
register(:redis, memoize: true) { RedisClient.new }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
# root dependencies
|
39
|
-
register(:logger) { Logger.new(STDOUT) }
|
39
|
+
register(:logger, memoize: true) { Logger.new(STDOUT) }
|
40
40
|
|
41
|
-
#
|
42
|
-
register(:random
|
41
|
+
# dependencies are not memoized by default (memoize: false)
|
42
|
+
register(:random) { rand(1000) }
|
43
43
|
end
|
44
44
|
|
45
45
|
container = Container.new # create container instance
|
@@ -69,8 +69,12 @@ class SmartCore::Container
|
|
69
69
|
#
|
70
70
|
# @api public
|
71
71
|
# @since 0.1.0
|
72
|
-
# @version 0.
|
73
|
-
def register(
|
72
|
+
# @version 0.3.0
|
73
|
+
def register(
|
74
|
+
dependency_name,
|
75
|
+
memoize: SmartCore::Container::Registry::DEFAULT_MEMOIZATION_BEHAVIOR,
|
76
|
+
&dependency_definition
|
77
|
+
)
|
74
78
|
@__container_definition_lock__.thread_safe do
|
75
79
|
DependencyCompatability::Definition.prevent_namespace_overlap!(self, dependency_name)
|
76
80
|
|
@@ -7,6 +7,12 @@ class SmartCore::Container::Registry
|
|
7
7
|
# @since 0.1.0
|
8
8
|
include Enumerable
|
9
9
|
|
10
|
+
# @return [Boolean]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
# @since 0.3.0
|
14
|
+
DEFAULT_MEMOIZATION_BEHAVIOR = false
|
15
|
+
|
10
16
|
# @return [Hash<Symbol,SmartCore::Container::Entity>]
|
11
17
|
#
|
12
18
|
# @api private
|
@@ -38,8 +44,8 @@ class SmartCore::Container::Registry
|
|
38
44
|
#
|
39
45
|
# @api private
|
40
46
|
# @since 0.1.0
|
41
|
-
# @version 0.
|
42
|
-
def register_dependency(name, memoize =
|
47
|
+
# @version 0.3.0
|
48
|
+
def register_dependency(name, memoize = DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition)
|
43
49
|
thread_safe { add_dependency(name, dependency_definition, memoize) }
|
44
50
|
end
|
45
51
|
|