smart_ioc 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/smart_ioc/bean_definitions_storage.rb +12 -2
- data/lib/smart_ioc/bean_factory.rb +1 -1
- data/lib/smart_ioc/container.rb +8 -0
- data/lib/smart_ioc/iocify.rb +11 -2
- data/lib/smart_ioc/version.rb +1 -1
- data/spec/smart_ioc/iocify_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cada3041d79cc078eda3cf08e8e54d0e5cf9c5b
|
4
|
+
data.tar.gz: f5ddaef04a1bdc97286501c4e66892e90a56a325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e07e1777d3866634ab0d2f4d847d9b73279ffa918ccf1d0bd7293d5cd4bcf7010b29b570ece63f36aff4fc364721a7595d53a1a33732554c9a9c88adab6c94a9
|
7
|
+
data.tar.gz: 98219fd6eab79278f393457320a131180618d358cf33230e05670344cad8957ec4849490ec370752069186d42c0f066d22b858aaa9c9e8f48a6fa29ec92128f8
|
data/Gemfile.lock
CHANGED
@@ -26,10 +26,20 @@ Existing bean details:
|
|
26
26
|
@collection.push(bean_definition)
|
27
27
|
end
|
28
28
|
|
29
|
+
def delete_by_class(klass)
|
30
|
+
klass_str = klass.to_s
|
31
|
+
bean = @collection.detect {|bd| bd.klass.to_s == klass_str}
|
32
|
+
|
33
|
+
if bean
|
34
|
+
@collection.delete(bean)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
# @param klass [Class] bean class
|
30
39
|
# @return bean definition [BeanDefinition] or nil
|
31
40
|
def find_by_class(klass)
|
32
|
-
|
41
|
+
klass_str = klass.to_s
|
42
|
+
@collection.detect {|bd| bd.klass.to_s == klass_str}
|
33
43
|
end
|
34
44
|
|
35
45
|
def filter_by(bean_name, package = nil, context = nil)
|
@@ -55,7 +65,7 @@ Existing bean details:
|
|
55
65
|
# @bean_name [Symbol] bean name
|
56
66
|
# @package [Symbol, nil] package name
|
57
67
|
# @context [Symbol, nil] context
|
58
|
-
# @raises Errors::AmbiguousBeanDefinition if multiple bean definitions are found
|
68
|
+
# @raises Errors::AmbiguousBeanDefinition if multiple bean definitions are found
|
59
69
|
def find(bean_name, package = nil, context = nil)
|
60
70
|
bds = filter_by_with_drop_to_default_context(bean_name, package, context)
|
61
71
|
|
data/lib/smart_ioc/container.rb
CHANGED
@@ -23,6 +23,14 @@ module SmartIoC
|
|
23
23
|
raise ArgumentError, "SmartIoC::Container should not be allocated. Use SmartIoC::Container.get_instance instead"
|
24
24
|
end
|
25
25
|
|
26
|
+
# @param klass [Class] bean class name
|
27
|
+
# @return nil
|
28
|
+
def unregister_bean(klass)
|
29
|
+
bean_definitions_storage.delete_by_class(klass)
|
30
|
+
clear_scopes
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
26
34
|
# @param bean_name [Symbol] bean name
|
27
35
|
# @param klass [Class] bean class name
|
28
36
|
# @param path [String] bean file absolute path
|
data/lib/smart_ioc/iocify.rb
CHANGED
@@ -35,8 +35,17 @@ module SmartIoC::Iocify
|
|
35
35
|
|
36
36
|
bean_definition = SmartIoC.get_bean_definition_by_class(self)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
if bean_definition
|
39
|
+
if bean_definition.path == file_path
|
40
|
+
# seems that file with bean definition was reloaded
|
41
|
+
# lets clear all scopes so we do not have
|
42
|
+
container = SmartIoC::Container.get_instance
|
43
|
+
container.unregister_bean(self)
|
44
|
+
container.force_clear_scopes
|
45
|
+
else
|
46
|
+
raise ArgumentError, "bean with for class #{self.to_s} was already defined in #{bean_definition.path}"
|
47
|
+
end
|
48
|
+
end
|
40
49
|
|
41
50
|
bean_definition = SmartIoC.register_bean(
|
42
51
|
bean_name: bean_name,
|
data/lib/smart_ioc/version.rb
CHANGED
@@ -10,4 +10,19 @@ describe SmartIoC::Iocify do
|
|
10
10
|
end
|
11
11
|
}.to raise_error(ArgumentError, "MyTestClass is not registered as bean. Add `bean :bean_name` declaration")
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
|
+
it 'reloads bean when file is reloaded' do
|
15
|
+
dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/utils')
|
16
|
+
SmartIoC.find_package_beans(:users, dir_path)
|
17
|
+
logger = SmartIoC.get_bean(:logger)
|
18
|
+
initial_object_id = logger.object_id
|
19
|
+
|
20
|
+
# reload file
|
21
|
+
load(File.join(dir_path, 'logger.rb'))
|
22
|
+
|
23
|
+
logger = SmartIoC.get_bean(:logger)
|
24
|
+
final_object_id = logger.object_id
|
25
|
+
|
26
|
+
expect(initial_object_id).not_to eq(final_object_id)
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_ioc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|