smart_ioc 0.3.7 → 0.3.8

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: a58c5f84034596665181c7a368aa35b2c9ed780e0dce715d538e4e142a921be4
4
- data.tar.gz: 462be2bd543accc11130c90f86589247116a4d939c62aaca8e71f57db99cca5d
3
+ metadata.gz: 935f8126a232eeb46445b817709b70a45d99c2212cd81fbc81782a217fbe409b
4
+ data.tar.gz: 6f433ae8f0514505f08eeb3cadda7856b456f28ed4d61f774bb7fee327914ce3
5
5
  SHA512:
6
- metadata.gz: 64c18ef92109604e6eef73fec45c2dd8c9b7c84b1e5472b5f3cdf5b3a800490fa7aec50b9de5a508c1c62abf9739f571cf7393a318eec2558d2b6fd1a978211a
7
- data.tar.gz: 1705b4a8b407707aaf00016f79c941a68250f52a1ef4e8071ad55c7f4f0c0fee03d786b3acfc40b59d8f6c2635cd7df65c7cb69e2505b07a72f7aac87b8c2ad1
6
+ metadata.gz: 9d1c0b83f8b812e062332d65756e90a6566f3e9934086dce23c6c163b52fb9e002eabcd746b3a757012bb3ee172728ccc72d0698078ae4fcee7f9790a28f5245
7
+ data.tar.gz: 27c53e6c7d8772fba4e21281c6dd89d9bc3f22431e6740ab484f1af6f705e21db0d1b53fd6e890b66b5c037b66cbe64031b7fe62068df554660a294677901d3e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.3.7)
4
+ smart_ioc (0.3.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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'
@@ -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.8"
3
3
  end
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.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: 2020-12-10 00:00:00.000000000 Z
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