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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2067f3974f1412037425a8615dd9143091f06ef
4
- data.tar.gz: 9ab33bd6d8a554bf1e77ad0a85bc04e7e8a6fb45
3
+ metadata.gz: 2cada3041d79cc078eda3cf08e8e54d0e5cf9c5b
4
+ data.tar.gz: f5ddaef04a1bdc97286501c4e66892e90a56a325
5
5
  SHA512:
6
- metadata.gz: c3415af0ff931fd21404f6e91ade5367c025395ce739cd05bfc2f98db175f5c60df36690e6e8f1b419ee10e2355e0f90ac0a7b113e4e4735c20f2de7d43f7999
7
- data.tar.gz: 82dc65927d8e00b79ae790e4f65b55f13f6adf3a19103024a0b810ec41ada75e662413d6705be8b72527541b950dccf03a33deca453cbe0d5ea419d05ee8c14f
6
+ metadata.gz: e07e1777d3866634ab0d2f4d847d9b73279ffa918ccf1d0bd7293d5cd4bcf7010b29b570ece63f36aff4fc364721a7595d53a1a33732554c9a9c88adab6c94a9
7
+ data.tar.gz: 98219fd6eab79278f393457320a131180618d358cf33230e05670344cad8957ec4849490ec370752069186d42c0f066d22b858aaa9c9e8f48a6fa29ec92128f8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.1.21)
4
+ smart_ioc (0.1.23)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- @collection.detect {|bd| bd.klass == klass}
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
 
@@ -63,7 +63,7 @@ class SmartIoC::BeanFactory
63
63
  )
64
64
 
65
65
  scope = get_scope(bean_definition)
66
- dep_bean = updated_beans[bd] || scope.get_bean(bd.class)
66
+ dep_bean = updated_beans[bd] || scope.get_bean(bd.klass)
67
67
 
68
68
  if !dep_bean
69
69
  dep_bean = get_bean(
@@ -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
@@ -35,8 +35,17 @@ module SmartIoC::Iocify
35
35
 
36
36
  bean_definition = SmartIoC.get_bean_definition_by_class(self)
37
37
 
38
- # skip if bean was registered
39
- return if bean_definition
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,
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.1.22"
2
+ VERSION = "0.1.23"
3
3
  end
@@ -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
- end
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.22
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-03-28 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler