smart_ioc 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e5c21e82ade291e0f2349e6d75807764104472899d1369275b8e43be1184f82
4
- data.tar.gz: 233217c7f8049bfaf40359cc599fc6f944f4a8e773da8a2b2c6059224dd283e4
3
+ metadata.gz: 4122153af2d77cfb9355497cf34a415aeb02bb9eb6cef8af6a4f467fa793df08
4
+ data.tar.gz: b31a912ab5cdb90c000fd1ab96d5ee62a3b60b8a839af5fc437aa93b855a79b8
5
5
  SHA512:
6
- metadata.gz: 49f4a74095dc772d17f3e5f2b9f749465c6b58f9fbb60309f1a4a772ecdcd4211200879f4ca7bc169e3b40c5695519273b7b729bfab4683f1f96d920fe41e505
7
- data.tar.gz: 3aafd25fb01683303a404692d92cf8becc533c1840ba1672eaac6329e0360a59bf44d1820eaab0517ef8c1f1326160f0e2ec000efb1b9933f48de8945ccf8eed
6
+ metadata.gz: cb497f0de22e9823795b179db0c003b029a1f4425dedb7d4983f6a6fb891c56f0d44cf2fed41c1098596cd07636fcd35ca376e564dc6813da00f0cf2c8a2b581
7
+ data.tar.gz: '08a61bbb285fb6c777caae491d56475d27761c102c41df5bf7c9b83c31619b227bd0dc6a0668fb3c1f1deb7af06472de6e91b015620bb56057a95b9c7306dcc7'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.5.1)
4
+ smart_ioc (0.5.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,11 +2,11 @@ class SmartIoC::BeanDefinitionsStorage
2
2
  include SmartIoC::Errors
3
3
 
4
4
  def initialize
5
- @collection = []
5
+ @collection = Hash.new { |h, k| h[k] = [] }
6
6
  end
7
7
 
8
8
  def clear_dependencies
9
- @collection.each do |bd|
9
+ @collection.values.flatten.each do |bd|
10
10
  bd.dependencies.each do |dependency|
11
11
  dependency.bean_definition = nil
12
12
  end
@@ -15,12 +15,12 @@ class SmartIoC::BeanDefinitionsStorage
15
15
 
16
16
  # @param bean_definition [BeanDefinition]
17
17
  def push(bean_definition)
18
- existing_bd = @collection.detect do |bd|
19
- bd == bean_definition
20
- end
18
+ bd_scope = @collection[bean_definition.name]
19
+
20
+ existing_bd = bd_scope.detect { |bd| bd == bean_definition }
21
21
 
22
22
  if existing_bd
23
- @collection.reject! { |bd| bd == existing_bd }
23
+ bd_scope.reject! { |bd| bd == bean_definition }
24
24
 
25
25
  message = <<~EOF
26
26
  \nReplacing bean definition...
@@ -34,16 +34,15 @@ class SmartIoC::BeanDefinitionsStorage
34
34
  puts message
35
35
  end
36
36
 
37
- @collection.push(bean_definition)
37
+ bd_scope.push(bean_definition)
38
38
  end
39
39
 
40
- def delete_by_class(klass)
41
- klass_str = klass.to_s
42
- bean = @collection.detect {|bd| bd.klass.to_s == klass_str}
40
+ def delete(bean_definition)
41
+ bd_scope = @collection[bean_definition.name]
43
42
 
44
- if bean
45
- @collection.delete(bean)
46
- end
43
+ bd_scope.delete_if { |bd| bd.klass.to_s == bean_definition.klass.to_s }
44
+
45
+ nil
47
46
  end
48
47
 
49
48
  # Returns bean definition for specific class
@@ -52,27 +51,23 @@ class SmartIoC::BeanDefinitionsStorage
52
51
  # @param context [Symbol]
53
52
  # @return bean definition [BeanDefinition] or nil
54
53
  def find_bean(bean_name, package, context)
55
- @collection.detect {|bd| bd.name == bean_name && bd.package == package && bd.context == context}
54
+ @collection[bean_name].detect do |bd|
55
+ bd.name == bean_name && bd.package == package && bd.context == context
56
+ end
56
57
  end
57
58
 
58
59
  def filter_by(bean_name, package = nil, context = nil)
59
- bean_definitions = @collection.select do |bd|
60
- bd.name == bean_name
61
- end
60
+ bd_scope = @collection[bean_name]
62
61
 
63
62
  if package
64
- bean_definitions = bean_definitions.select do |bd|
65
- bd.package == package
66
- end
63
+ bd_scope = bd_scope.select { |bd| bd.package == package }
67
64
  end
68
65
 
69
66
  if context
70
- bean_definitions = bean_definitions.select do |bd|
71
- bd.context == context
72
- end
67
+ bd_scope = bean_definitions.select { |bd| bd.context == context }
73
68
  end
74
69
 
75
- bean_definitions
70
+ bd_scope
76
71
  end
77
72
 
78
73
  # @bean_name [Symbol] bean name
@@ -106,26 +101,18 @@ class SmartIoC::BeanDefinitionsStorage
106
101
  # @package [Symbol, nil] package name
107
102
  # @context [Symbol, nil] context
108
103
  def filter_by_with_drop_to_default_context(bean_name, package = nil, context = nil)
109
- bean_definitions = @collection.select do |bd|
110
- bd.name == bean_name
111
- end
104
+ bd_scope = @collection[bean_name]
112
105
 
113
106
  if package
114
- bean_definitions = bean_definitions.select do |bd|
115
- bd.package == package
116
- end
107
+ bd_scope = bd_scope.select { |bd| bd.package == package }
117
108
  end
118
109
 
119
110
  if context
120
- context_bean_definitions = bean_definitions.select do |bd|
121
- bd.context == context
122
- end
111
+ context_bean_definitions = bd_scope.select { |bd| bd.context == context }
123
112
 
124
- if !context_bean_definitions.empty?
125
- bean_definitions = context_bean_definitions
126
- end
113
+ bd_scope = context_bean_definitions if context_bean_definitions.any?
127
114
  end
128
115
 
129
- bean_definitions
116
+ bd_scope
130
117
  end
131
118
  end
@@ -12,7 +12,6 @@ class SmartIoC::BeanFactory
12
12
  @singleton_scope = SmartIoC::Scopes::Singleton.new
13
13
  @prototype_scope = SmartIoC::Scopes::Prototype.new
14
14
  @thread_scope = SmartIoC::Scopes::Request.new
15
- @semaphore = Mutex.new
16
15
  end
17
16
 
18
17
  def clear_scopes
@@ -2,6 +2,7 @@ class SmartIoC::BeanFileLoader
2
2
  def initialize
3
3
  @loaded_locations = {}
4
4
  @load_proc = Proc.new { |location| load(location) }
5
+ @semaphore = Mutex.new
5
6
  end
6
7
 
7
8
  def set_load_proc(&block)
@@ -17,7 +18,10 @@ class SmartIoC::BeanFileLoader
17
18
  locations.each do |location|
18
19
  next if @loaded_locations.has_key?(location)
19
20
  @loaded_locations[location] = true
20
- @load_proc.call(location)
21
+
22
+ @semaphore.synchronize do
23
+ @load_proc.call(location)
24
+ end
21
25
  end
22
26
 
23
27
  nil
@@ -19,10 +19,10 @@ module SmartIoC
19
19
  raise ArgumentError, "SmartIoC::Container should not be allocated. Use SmartIoC::Container.get_instance instead"
20
20
  end
21
21
 
22
- # @param klass [Class] bean class name
22
+ # @param klass [BeanDefinition] bean class name
23
23
  # @return nil
24
- def unregister_bean(klass)
25
- bean_definitions_storage.delete_by_class(klass)
24
+ def unregister_bean(bean_definition)
25
+ bean_definitions_storage.delete(bean_definition)
26
26
  clear_scopes
27
27
  nil
28
28
  end
@@ -74,9 +74,8 @@ module SmartIoC::Iocify
74
74
  if bean_definition.path == file_path
75
75
  # seems that file with bean definition was reloaded
76
76
  # lets clear all scopes so we do not have
77
- container = SmartIoC::Container.get_instance
78
- container.unregister_bean(self)
79
- container.force_clear_scopes
77
+ SmartIoC::Container.get_instance.unregister_bean(bean_definition)
78
+ SmartIoC::Container.get_instance.force_clear_scopes
80
79
  else
81
80
  raise ArgumentError, "bean with for class #{self.to_s} was already defined in #{bean_definition.path}"
82
81
  end
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_ioc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -120,7 +119,6 @@ homepage: http://github.com/droidlabs/smart_ioc
120
119
  licenses:
121
120
  - MIT
122
121
  metadata: {}
123
- post_install_message:
124
122
  rdoc_options: []
125
123
  require_paths:
126
124
  - lib
@@ -135,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
133
  - !ruby/object:Gem::Version
136
134
  version: '0'
137
135
  requirements: []
138
- rubygems_version: 3.5.10
139
- signing_key:
136
+ rubygems_version: 3.6.9
140
137
  specification_version: 4
141
138
  summary: Inversion of Control Container
142
139
  test_files: