smart_ioc 0.5.0 → 0.5.1

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
  SHA256:
3
- metadata.gz: 9d8b979ba9bf2ec07fbd542a155af2fad52bb85fdbffece8cc50f1e3132c8d77
4
- data.tar.gz: 47478f2706b6e5a262af7de3974825ca8d01b48839716c14d9996749421b390a
3
+ metadata.gz: 5e5c21e82ade291e0f2349e6d75807764104472899d1369275b8e43be1184f82
4
+ data.tar.gz: 233217c7f8049bfaf40359cc599fc6f944f4a8e773da8a2b2c6059224dd283e4
5
5
  SHA512:
6
- metadata.gz: 530e72ce702c8f328ca21ce183d6f511216cb957511f026b52dbcd110b9fc0b21e418e2005f549cfcea75f1b6e6b7b1de3134e476609a19588755434c058aefb
7
- data.tar.gz: 75ac2416d31d4e067d9a4e3fb1966edfa3a929771fad2760f7506bf50a8e8b60c0a7b1d0fa72120856230ceb62212256a402ebebd981b548e17a4e5134da73ed
6
+ metadata.gz: 49f4a74095dc772d17f3e5f2b9f749465c6b58f9fbb60309f1a4a772ecdcd4211200879f4ca7bc169e3b40c5695519273b7b729bfab4683f1f96d920fe41e505
7
+ data.tar.gz: 3aafd25fb01683303a404692d92cf8becc533c1840ba1672eaac6329e0360a59bf44d1820eaab0517ef8c1f1326160f0e2ec000efb1b9933f48de8945ccf8eed
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.4
1
+ 3.2.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.5.0)
4
+ smart_ioc (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -67,12 +67,14 @@ class SmartIoC::BeanDefinition
67
67
 
68
68
  def preload
69
69
  @dependencies.each do |dep|
70
- SmartIoC::Container.get_instance.get_bean(
71
- dep.ref || dep.bean_name,
70
+ bd = SmartIoC.get_bean_definition(
71
+ dep.ref,
72
72
  package: dep.package,
73
73
  parent_bean_definition: self,
74
74
  parent_bean_name: name,
75
- ).class._smart_ioc_preload_; nil
75
+ )
76
+
77
+ bd.preload
76
78
  end
77
79
  end
78
80
  end
@@ -46,12 +46,6 @@ class SmartIoC::BeanDefinitionsStorage
46
46
  end
47
47
  end
48
48
 
49
- # @param klass [Class] bean class
50
- # @return bean definition [BeanDefinition] or nil
51
- def find_by_class(klass)
52
- @collection.detect {|bd| bd.klass == klass}
53
- end
54
-
55
49
  # Returns bean definition for specific class
56
50
  # @param bean_name [Symbol]
57
51
  # @param package [Symbol]
@@ -32,16 +32,7 @@ class SmartIoC::BeanFactory
32
32
  # @raise [ArgumentError] if bean is not found
33
33
  # @raise [ArgumentError] if ambiguous bean definition was found
34
34
  def get_bean(bean_name, package: nil, parent_bean_definition: nil, context: nil, parent_bean_name: nil)
35
- check_arg(bean_name, :bean_name, Symbol)
36
- check_arg(package, :package, Symbol) if package
37
- check_arg(parent_bean_definition, :parent_bean_definition, SmartIoC::BeanDefinition) if parent_bean_definition
38
- check_arg(context, :context, Symbol) if context
39
-
40
- @bean_file_loader.require_bean(bean_name)
41
-
42
- parent_package_name = parent_bean_definition ? parent_bean_definition.package : nil
43
- context = autodetect_context(bean_name, package, parent_package_name, context, parent_bean_name)
44
- bean_definition = @bean_definitions_storage.find(bean_name, package, context, parent_package_name)
35
+ bean_definition = get_bean_definition(bean_name, package:, parent_bean_definition:, context:, parent_bean_name:)
45
36
  scope = get_scope(bean_definition)
46
37
  bean = scope.get_bean(bean_definition.klass)
47
38
 
@@ -56,6 +47,19 @@ class SmartIoC::BeanFactory
56
47
  raise e
57
48
  end
58
49
 
50
+ def get_bean_definition(bean_name, package: nil, context: nil, parent_bean_definition: nil, parent_bean_name: nil)
51
+ check_arg(bean_name, :bean_name, Symbol)
52
+ check_arg(package, :package, Symbol) if package
53
+ check_arg(parent_bean_definition, :parent_bean_definition, SmartIoC::BeanDefinition) if parent_bean_definition
54
+ check_arg(context, :context, Symbol) if context
55
+
56
+ @bean_file_loader.require_bean(bean_name)
57
+
58
+ parent_package_name = parent_bean_definition ? parent_bean_definition.package : nil
59
+ context = autodetect_context(bean_name, package, parent_package_name, context, parent_bean_name)
60
+ bean_definition = @bean_definitions_storage.find(bean_name, package, context, parent_package_name)
61
+ end
62
+
59
63
  private
60
64
 
61
65
  def init_bean(bean_definition)
@@ -90,10 +90,14 @@ module SmartIoC
90
90
  # @param package [Symbol]
91
91
  # @param context [Symbol]
92
92
  # return [BeanDefinition]
93
- def get_bean_definition(bean_name, package, context)
93
+ def find_bean_definition(bean_name, package, context)
94
94
  bean_definitions_storage.find_bean(bean_name, package, context)
95
95
  end
96
96
 
97
+ def get_bean_definition(...)
98
+ bean_factory.get_bean_definition(...)
99
+ end
100
+
97
101
  # Sets new load proc
98
102
  # for those who use active support dependency loader
99
103
  # one can use
@@ -68,7 +68,7 @@ module SmartIoC::Iocify
68
68
  file_path ||= caller[0].split(':').first
69
69
  package ||= SmartIoC::BeanLocations.get_bean_package(file_path)
70
70
  context ||= SmartIoC::Container::DEFAULT_CONTEXT
71
- bean_definition = SmartIoC.get_bean_definition(bean_name, package, context)
71
+ bean_definition = SmartIoC.find_bean_definition(bean_name, package, context)
72
72
 
73
73
  if bean_definition
74
74
  if bean_definition.path == file_path
@@ -168,9 +168,5 @@ module SmartIoC::Iocify
168
168
 
169
169
  nil
170
170
  end
171
-
172
- def _smart_ioc_preload_
173
- @bean_definition&.preload; nil
174
- end
175
171
  end
176
172
  end
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
data/lib/smart_ioc.rb CHANGED
@@ -80,6 +80,7 @@ module SmartIoC
80
80
  container_methods = [
81
81
  :register_bean,
82
82
  :get_bean_definition,
83
+ :find_bean_definition,
83
84
  :set_extra_context_for_package,
84
85
  :get_bean,
85
86
  :clear_scopes,
@@ -32,7 +32,7 @@ describe Object do
32
32
  factory_method: :my_method, context: :test
33
33
  end
34
34
 
35
- @bean_definition = SmartIoC.get_bean_definition(:my_bean, :my_package, :test)
35
+ @bean_definition = SmartIoC.find_bean_definition(:my_bean, :my_package, :test)
36
36
  end
37
37
 
38
38
  it { expect(@bean_definition.name).to eq(:my_bean) }
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
11
+ date: 2024-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.5.11
138
+ rubygems_version: 3.5.10
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Inversion of Control Container