smart_ioc 0.3.7 → 0.3.9

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: a58c5f84034596665181c7a368aa35b2c9ed780e0dce715d538e4e142a921be4
4
- data.tar.gz: 462be2bd543accc11130c90f86589247116a4d939c62aaca8e71f57db99cca5d
3
+ metadata.gz: 1952e81bd1c8dd7759dad214db0629d9d7deb1f51ead352d85d76c7375207903
4
+ data.tar.gz: b6a18802edbb15c81e9de29ac346e69a126bb05ec743a91c3abddecc31219f75
5
5
  SHA512:
6
- metadata.gz: 64c18ef92109604e6eef73fec45c2dd8c9b7c84b1e5472b5f3cdf5b3a800490fa7aec50b9de5a508c1c62abf9739f571cf7393a318eec2558d2b6fd1a978211a
7
- data.tar.gz: 1705b4a8b407707aaf00016f79c941a68250f52a1ef4e8071ad55c7f4f0c0fee03d786b3acfc40b59d8f6c2635cd7df65c7cb69e2505b07a72f7aac87b8c2ad1
6
+ metadata.gz: fed6928dafae5cf284d1cb1cec295737c0b2823e6f053e62444f6c688bf73e02be5b70a46b95c1f35cf87ac0b7e96d3483a6e72fb058d96c6b239af23f01f013
7
+ data.tar.gz: 7028318cd0bcaa4752c44a221af6a4f7b96eccdeadd2e1676aa90a5fb1547817035e8f7a8f346e20a527bdf5bd365ca9cda82f73e51bca918fe77c09d72b512a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.7.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.3.7)
4
+ smart_ioc (0.3.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -47,4 +47,4 @@ DEPENDENCIES
47
47
  smart_ioc!
48
48
 
49
49
  BUNDLED WITH
50
- 2.1.2
50
+ 2.3.25
@@ -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) || nil,
20
- package: instance_variable_get(:@package) || 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) || nil,
23
- context: instance_variable_get(:@context) || nil,
24
- after_init: instance_variable_get(:@after_init) || nil
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
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.9"
3
3
  end
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.7
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: 2020-12-10 00:00:00.000000000 Z
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.2
138
+ rubygems_version: 3.1.4
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: Inversion of Control Container