smart_ioc 0.3.7 → 0.3.9
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 +4 -4
- data/.ruby-version +1 -1
- data/Gemfile.lock +2 -2
- data/lib/smart_ioc/bean.rb +32 -6
- data/lib/smart_ioc/string_utils.rb +13 -0
- data/lib/smart_ioc/version.rb +1 -1
- data/lib/smart_ioc.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1952e81bd1c8dd7759dad214db0629d9d7deb1f51ead352d85d76c7375207903
|
4
|
+
data.tar.gz: b6a18802edbb15c81e9de29ac346e69a126bb05ec743a91c3abddecc31219f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fed6928dafae5cf284d1cb1cec295737c0b2823e6f053e62444f6c688bf73e02be5b70a46b95c1f35cf87ac0b7e96d3483a6e72fb058d96c6b239af23f01f013
|
7
|
+
data.tar.gz: 7028318cd0bcaa4752c44a221af6a4f7b96eccdeadd2e1676aa90a5fb1547817035e8f7a8f346e20a527bdf5bd365ca9cda82f73e51bca918fe77c09d72b512a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/Gemfile.lock
CHANGED
data/lib/smart_ioc/bean.rb
CHANGED
@@ -9,19 +9,45 @@ def bean(bean_name, &proc)
|
|
9
9
|
klass.instance_variable_set(:@anonymous_bean, true)
|
10
10
|
klass.instance_exec(&proc)
|
11
11
|
|
12
|
+
str = SmartIoC::StringUtils
|
12
13
|
file_path = caller[0].split(':').first
|
13
|
-
package = SmartIoC::BeanLocations.get_bean_package(file_path)
|
14
|
+
package = klass.instance_variable_get(:@package) || SmartIoC::BeanLocations.get_bean_package(file_path)
|
15
|
+
context = klass.instance_variable_get(:@context) || :default
|
16
|
+
|
17
|
+
if package.nil?
|
18
|
+
raise ArgumentError, "package is not defined for bean :#{bean_name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
package_mod = str.camelize(package)
|
22
|
+
context_mod = str.camelize(context || :default)
|
23
|
+
|
24
|
+
class_name = str.camelize(bean_name)
|
25
|
+
klass_name = "#{package_mod}::#{context_mod}::#{class_name}"
|
26
|
+
|
27
|
+
eval(
|
28
|
+
%Q(
|
29
|
+
module #{package_mod}
|
30
|
+
module #{context_mod}
|
31
|
+
if constants.include?(:"#{class_name}")
|
32
|
+
remove_const :"#{class_name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#{klass_name} = klass
|
38
|
+
)
|
39
|
+
)
|
14
40
|
|
15
41
|
klass.instance_exec do
|
16
42
|
bean(
|
17
43
|
bean_name,
|
18
44
|
file_path: file_path,
|
19
|
-
scope: instance_variable_get(:@scope)
|
20
|
-
package:
|
45
|
+
scope: instance_variable_get(:@scope),
|
46
|
+
package: package,
|
21
47
|
instance: instance_variable_get(:@instance) || false,
|
22
|
-
factory_method: instance_variable_get(:@factory_method)
|
23
|
-
context:
|
24
|
-
after_init: instance_variable_get(:@after_init)
|
48
|
+
factory_method: instance_variable_get(:@factory_method),
|
49
|
+
context: context,
|
50
|
+
after_init: instance_variable_get(:@after_init),
|
25
51
|
)
|
26
52
|
end
|
27
53
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SmartIoC
|
2
|
+
class StringUtils
|
3
|
+
class << self
|
4
|
+
def camelize(term)
|
5
|
+
string = term.to_s
|
6
|
+
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
7
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
|
8
|
+
string.gsub!("/".freeze, "::".freeze)
|
9
|
+
string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/smart_ioc/version.rb
CHANGED
data/lib/smart_ioc.rb
CHANGED
@@ -15,6 +15,7 @@ module SmartIoC
|
|
15
15
|
autoload :InjectMetadata, 'smart_ioc/inject_metadata'
|
16
16
|
autoload :Iocify, 'smart_ioc/iocify'
|
17
17
|
autoload :Scopes, 'smart_ioc/scopes'
|
18
|
+
autoload :StringUtils, 'smart_ioc/string_utils'
|
18
19
|
|
19
20
|
module Scopes
|
20
21
|
autoload :Bean, 'smart_ioc/scopes/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.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/smart_ioc/scopes/prototype.rb
|
92
92
|
- lib/smart_ioc/scopes/request.rb
|
93
93
|
- lib/smart_ioc/scopes/singleton.rb
|
94
|
+
- lib/smart_ioc/string_utils.rb
|
94
95
|
- lib/smart_ioc/version.rb
|
95
96
|
- smart_ioc.gemspec
|
96
97
|
- spec/smart_ioc/bean_definition_spec.rb
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
rubygems_version: 3.1.
|
138
|
+
rubygems_version: 3.1.4
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Inversion of Control Container
|