smart_ioc 0.2.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe SmartIoC do
4
+ it {
5
+ SmartIoC.clear
6
+ SmartIoC.benchmark_mode(true)
7
+
8
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/admins')
9
+ SmartIoC.find_package_beans(:admins, dir_path)
10
+
11
+ SmartIoC.benchmark_mode(false)
12
+ }
13
+ end
@@ -1,20 +1,22 @@
1
- $data ||= {}
2
-
3
1
  class AdminsDAO
4
2
  include SmartIoC::Iocify
5
3
 
6
- bean :dao, instance: false
4
+ bean :dao, instance: false, after_init: :setup
7
5
 
8
6
  inject :config
9
7
 
10
8
  class << self
9
+ def setup
10
+ @data = {}
11
+ end
12
+
11
13
  def insert(entity)
12
14
  config.app_name
13
- $data[entity.id] = entity
15
+ @data[entity.id] = entity
14
16
  end
15
17
 
16
18
  def get(id)
17
- $data[id]
19
+ @data[id]
18
20
  end
19
21
  end
20
22
  end
@@ -4,6 +4,9 @@ class AdminsRepository
4
4
  bean :repository
5
5
 
6
6
  inject :dao
7
+ inject :users_creator
8
+
9
+ public :users_creator
7
10
 
8
11
  def put(user)
9
12
  dao.insert(user)
@@ -1,11 +1,13 @@
1
1
  class UsersDAO
2
2
  include SmartIoC::Iocify
3
3
 
4
- bean :dao, instance: false
5
-
6
- @data = {}
4
+ bean :dao, instance: false, after_init: :setup
7
5
 
8
6
  class << self
7
+ def setup
8
+ @data = {}
9
+ end
10
+
9
11
  def insert(entity)
10
12
  @data[entity.id] = entity
11
13
  end
@@ -6,6 +6,8 @@ class UsersRepository
6
6
  inject :users_creator # just for testing purposes (circular load check)
7
7
  inject :dao
8
8
 
9
+ public :users_creator
10
+
9
11
  def put(user)
10
12
  dao.insert(user)
11
13
  end
@@ -1,9 +1,13 @@
1
1
  class Config
2
2
  include SmartIoC::Iocify
3
3
 
4
- bean :config, factory_method: :get_config
4
+ bean :config, factory_method: :get_config, after_init: :setup
5
5
 
6
6
  class TestConfig
7
+ def setup
8
+ # do nothing; only for testing purposes
9
+ end
10
+
7
11
  def app_name
8
12
  'SmartIoC'
9
13
  end
@@ -9,7 +9,7 @@ describe 'Factory Method' do
9
9
 
10
10
  inject :test_config
11
11
 
12
- attr_reader :test_config
12
+ public :test_config
13
13
  end
14
14
 
15
15
 
@@ -20,7 +20,7 @@ describe 'Factory Method' do
20
20
 
21
21
  inject :test_config
22
22
 
23
- attr_reader :test_config
23
+ public :test_config
24
24
  end
25
25
 
26
26
  class TestConfig
@@ -52,7 +52,7 @@ describe 'Factory Method' do
52
52
  before :all do
53
53
  class SingletonBean
54
54
  include SmartIoC::Iocify
55
-
55
+
56
56
  bean :singleton_bean, package: :cross_refference
57
57
  end
58
58
 
@@ -61,10 +61,10 @@ describe 'Factory Method' do
61
61
 
62
62
  bean :other_singleton_bean, package: :cross_refference
63
63
  end
64
-
64
+
65
65
  class FactoryConfig
66
66
  include SmartIoC::Iocify
67
-
67
+
68
68
  bean :factory_config, factory_method: :build, package: :cross_refference
69
69
 
70
70
  inject :singleton_bean
@@ -85,7 +85,7 @@ describe 'Factory Method' do
85
85
 
86
86
  class FactoryLogger
87
87
  include SmartIoC::Iocify
88
-
88
+
89
89
  bean :factory_logger, factory_method: :build, package: :cross_refference
90
90
 
91
91
  inject :factory_config
@@ -99,7 +99,7 @@ describe 'Factory Method' do
99
99
  @singleton_bean = singleton_bean
100
100
  end
101
101
  end
102
-
102
+
103
103
  def build
104
104
  Logger.new(factory_config, singleton_bean)
105
105
  end
@@ -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_by_class(BeanClass)
35
+ @bean_definition = SmartIoC.get_bean_definition(:my_bean, :my_package, :test)
36
36
  end
37
37
 
38
38
  it { expect(@bean_definition.name).to eq(:my_bean) }
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe SmartIoC::Container do
4
+ before :all do
5
+ SmartIoC.clear
6
+
7
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/admins')
8
+ SmartIoC.find_package_beans(:admins, dir_path)
9
+
10
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/utils')
11
+ SmartIoC.find_package_beans(:utils, dir_path)
12
+
13
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/users')
14
+ SmartIoC.find_package_beans(:users, dir_path)
15
+
16
+ @container = SmartIoC.container
17
+ end
18
+
19
+ it 'loads recursive beans' do
20
+ users_creator = @container.get_bean(:users_creator)
21
+ uc2 = users_creator.send(:repository).users_creator
22
+ expect(users_creator).to eq(uc2)
23
+ end
24
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_ioc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-12 00:00:00.000000000 Z
11
+ date: 2020-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,7 @@ files:
73
73
  - docs/index.md
74
74
  - lib/smart_ioc.rb
75
75
  - lib/smart_ioc/args.rb
76
+ - lib/smart_ioc/bean.rb
76
77
  - lib/smart_ioc/bean_definition.rb
77
78
  - lib/smart_ioc/bean_definitions_storage.rb
78
79
  - lib/smart_ioc/bean_dependency.rb
@@ -87,7 +88,6 @@ files:
87
88
  - lib/smart_ioc/iocify.rb
88
89
  - lib/smart_ioc/railtie.rb
89
90
  - lib/smart_ioc/scopes.rb
90
- - lib/smart_ioc/scopes/bean.rb
91
91
  - lib/smart_ioc/scopes/prototype.rb
92
92
  - lib/smart_ioc/scopes/request.rb
93
93
  - lib/smart_ioc/scopes/singleton.rb
@@ -98,6 +98,7 @@ files:
98
98
  - spec/smart_ioc/bean_file_loader_spec.rb
99
99
  - spec/smart_ioc/bean_locations_spec.rb
100
100
  - spec/smart_ioc/bean_locator_spec.rb
101
+ - spec/smart_ioc/benchmark_mode_spec.rb
101
102
  - spec/smart_ioc/container_spec.rb
102
103
  - spec/smart_ioc/example/admins/repository/admins_dao.rb
103
104
  - spec/smart_ioc/example/admins/repository/admins_repository.rb
@@ -111,6 +112,7 @@ files:
111
112
  - spec/smart_ioc/factory_method_spec.rb
112
113
  - spec/smart_ioc/iocify_spec.rb
113
114
  - spec/smart_ioc/object_spec.rb
115
+ - spec/smart_ioc/recursive_spec.rb
114
116
  - spec/smart_ioc/smart_ioc_spec.rb
115
117
  - spec/spec_helper.rb
116
118
  homepage: http://github.com/droidlabs/smart_ioc
@@ -132,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  - !ruby/object:Gem::Version
133
135
  version: '0'
134
136
  requirements: []
135
- rubyforge_project:
136
- rubygems_version: 2.5.2
137
+ rubygems_version: 3.0.3
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: Inversion of Control Container
@@ -143,6 +144,7 @@ test_files:
143
144
  - spec/smart_ioc/bean_file_loader_spec.rb
144
145
  - spec/smart_ioc/bean_locations_spec.rb
145
146
  - spec/smart_ioc/bean_locator_spec.rb
147
+ - spec/smart_ioc/benchmark_mode_spec.rb
146
148
  - spec/smart_ioc/container_spec.rb
147
149
  - spec/smart_ioc/example/admins/repository/admins_dao.rb
148
150
  - spec/smart_ioc/example/admins/repository/admins_repository.rb
@@ -156,5 +158,6 @@ test_files:
156
158
  - spec/smart_ioc/factory_method_spec.rb
157
159
  - spec/smart_ioc/iocify_spec.rb
158
160
  - spec/smart_ioc/object_spec.rb
161
+ - spec/smart_ioc/recursive_spec.rb
159
162
  - spec/smart_ioc/smart_ioc_spec.rb
160
163
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
- class SmartIoC::Scopes::Bean
2
- attr_reader :bean, :loaded
3
-
4
- def initialize(bean, loaded)
5
- @bean = bean
6
- @loaded = loaded
7
- end
8
-
9
- def set_bean(bean, loaded)
10
- @bean = bean
11
- @loaded = loaded
12
- end
13
- end