smart_ioc 0.3.7 → 0.3.8
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.rb +1 -0
- 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
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 935f8126a232eeb46445b817709b70a45d99c2212cd81fbc81782a217fbe409b
|
4
|
+
data.tar.gz: 6f433ae8f0514505f08eeb3cadda7856b456f28ed4d61f774bb7fee327914ce3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d1c0b83f8b812e062332d65756e90a6566f3e9934086dce23c6c163b52fb9e002eabcd746b3a757012bb3ee172728ccc72d0698078ae4fcee7f9790a28f5245
|
7
|
+
data.tar.gz: 27c53e6c7d8772fba4e21281c6dd89d9bc3f22431e6740ab484f1af6f705e21db0d1b53fd6e890b66b5c037b66cbe64031b7fe62068df554660a294677901d3e
|
data/Gemfile.lock
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'
|
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
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.8
|
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: 2021-01-07 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
|