smart_ioc 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +3 -0
  4. data/.yardops +1 -0
  5. data/Gemfile +9 -0
  6. data/Gemfile.lock +32 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +91 -0
  9. data/Rakefile +1 -0
  10. data/lib/smart_ioc/bean_definition.rb +77 -0
  11. data/lib/smart_ioc/bean_definitions_storage.rb +79 -0
  12. data/lib/smart_ioc/bean_dependency.rb +18 -0
  13. data/lib/smart_ioc/bean_factory.rb +230 -0
  14. data/lib/smart_ioc/bean_file_loader.rb +26 -0
  15. data/lib/smart_ioc/bean_locations.rb +71 -0
  16. data/lib/smart_ioc/bean_locator.rb +32 -0
  17. data/lib/smart_ioc/container.rb +143 -0
  18. data/lib/smart_ioc/extra_package_contexts.rb +29 -0
  19. data/lib/smart_ioc/inject_metadata.rb +13 -0
  20. data/lib/smart_ioc/iocify.rb +101 -0
  21. data/lib/smart_ioc/scopes/prototype.rb +26 -0
  22. data/lib/smart_ioc/scopes/request.rb +35 -0
  23. data/lib/smart_ioc/scopes/singleton.rb +31 -0
  24. data/lib/smart_ioc/scopes.rb +2 -0
  25. data/lib/smart_ioc/version.rb +3 -0
  26. data/lib/smart_ioc.rb +44 -0
  27. data/smart_ioc.gemspec +23 -0
  28. data/spec/smart_ioc/bean_definition_spec.rb +29 -0
  29. data/spec/smart_ioc/bean_locator_spec.rb +27 -0
  30. data/spec/smart_ioc/example/admins/repository/admins_dao.rb +20 -0
  31. data/spec/smart_ioc/example/admins/repository/admins_repository.rb +15 -0
  32. data/spec/smart_ioc/example/admins/repository/test/admins_repository.rb +17 -0
  33. data/spec/smart_ioc/example/users/repository/users_dao.rb +17 -0
  34. data/spec/smart_ioc/example/users/repository/users_repository.rb +16 -0
  35. data/spec/smart_ioc/example/users/services/users_creator.rb +15 -0
  36. data/spec/smart_ioc/example/users/user.rb +8 -0
  37. data/spec/smart_ioc/example/utils/config.rb +15 -0
  38. data/spec/smart_ioc/example/utils/logger.rb +21 -0
  39. data/spec/smart_ioc/object_spec.rb +45 -0
  40. data/spec/smart_ioc/smart_ioc_spec.rb +43 -0
  41. data/spec/spec_helper.rb +8 -0
  42. metadata +126 -0
@@ -0,0 +1,21 @@
1
+ class LoggerFactory
2
+ include SmartIoC::Iocify
3
+
4
+ class SmartIoCLogger
5
+ end
6
+
7
+ class SimpleLogger
8
+ end
9
+
10
+ bean :logger, factory_method: :get_logger
11
+
12
+ inject :config
13
+
14
+ def get_logger
15
+ if config.app_name == 'SmartIoC'
16
+ SmartIoCLogger.new
17
+ else
18
+ SimpleLogger.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ describe '::inject' do
5
+ before :all do
6
+ class TestClass
7
+ include SmartIoC::Iocify
8
+
9
+ bean :test_class, package: :test, context: :test
10
+
11
+ inject :config
12
+ inject :logger, ref: :test_logger
13
+ end
14
+
15
+ @test_class = TestClass.allocate
16
+ end
17
+
18
+ it {expect(@test_class.private_methods.include?(:config)).to eq(true) }
19
+ it {expect(@test_class.private_methods.include?(:logger)).to eq(true) }
20
+ end
21
+
22
+ describe '::bean' do
23
+ before :all do
24
+ class BeanClass
25
+ include SmartIoC::Iocify
26
+
27
+ bean :my_bean, scope: :request, package: :my_package, instance: false,
28
+ factory_method: :my_method, context: :test
29
+ end
30
+ end
31
+
32
+ it {
33
+ bean_definition = SmartIoC::Container.get_instance.get_bean_definition_by_class(BeanClass)
34
+
35
+ expect(bean_definition.name).to eq(:my_bean)
36
+ expect(bean_definition.package).to eq(:my_package)
37
+ expect(bean_definition.path).to match(/object_spec.rb/)
38
+ expect(bean_definition.klass).to eq(BeanClass)
39
+ expect(bean_definition.scope).to eq(:request)
40
+ expect(bean_definition.instance).to eq(false)
41
+ expect(bean_definition.factory_method).to eq(:my_method)
42
+ expect(bean_definition.context).to eq(:test)
43
+ }
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe SmartIoC do
4
+ before :all do
5
+ SmartIoC.clear
6
+
7
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/users')
8
+ SmartIoC.find_package_beans(:users, dir_path)
9
+
10
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/admins')
11
+ SmartIoC.find_package_beans(:admins, dir_path)
12
+
13
+ dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/utils')
14
+ SmartIoC.find_package_beans(:utils, dir_path)
15
+
16
+ @container = SmartIoC::Container.get_instance
17
+ end
18
+
19
+ it 'sets beans' do
20
+ users_creator = @container.get_bean(:users_creator)
21
+ users_creator.create(1, 'test@test.com')
22
+
23
+ repository = @container.get_bean(:repository, package: :admins)
24
+
25
+ expect(repository.get(1)).to be_a(User)
26
+ expect(users_creator.send(:repository)).to be_a(AdminsRepository)
27
+ expect(users_creator.send(:logger)).to be_a(LoggerFactory::SmartIoCLogger)
28
+ end
29
+
30
+ it 'sets beans with extra package context' do
31
+ SmartIoC::Container.get_instance.set_extra_context_for_package(:admins, :test)
32
+ SmartIoC::Container.get_instance.force_clear_scopes
33
+
34
+ users_creator = @container.get_bean(:users_creator)
35
+ users_creator.create(1, 'test@test.com')
36
+
37
+ repository = @container.get_bean(:repository, package: :admins)
38
+
39
+ expect(users_creator.send(:repository)).to eq(TestAdminsRepository)
40
+ expect(repository.get(1)).to be_a(User)
41
+ expect(users_creator.send(:logger)).to be_a(LoggerFactory::SmartIoCLogger)
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'smart_ioc'
4
+ require 'byebug'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_ioc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.13
5
+ platform: ruby
6
+ authors:
7
+ - Ruslan Gatiyatov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Inversion of Control Container
42
+ email:
43
+ - ruslan@droidlabs.pro
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - ".yardops"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/smart_ioc.rb
57
+ - lib/smart_ioc/bean_definition.rb
58
+ - lib/smart_ioc/bean_definitions_storage.rb
59
+ - lib/smart_ioc/bean_dependency.rb
60
+ - lib/smart_ioc/bean_factory.rb
61
+ - lib/smart_ioc/bean_file_loader.rb
62
+ - lib/smart_ioc/bean_locations.rb
63
+ - lib/smart_ioc/bean_locator.rb
64
+ - lib/smart_ioc/container.rb
65
+ - lib/smart_ioc/extra_package_contexts.rb
66
+ - lib/smart_ioc/inject_metadata.rb
67
+ - lib/smart_ioc/iocify.rb
68
+ - lib/smart_ioc/scopes.rb
69
+ - lib/smart_ioc/scopes/prototype.rb
70
+ - lib/smart_ioc/scopes/request.rb
71
+ - lib/smart_ioc/scopes/singleton.rb
72
+ - lib/smart_ioc/version.rb
73
+ - smart_ioc.gemspec
74
+ - spec/smart_ioc/bean_definition_spec.rb
75
+ - spec/smart_ioc/bean_locator_spec.rb
76
+ - spec/smart_ioc/example/admins/repository/admins_dao.rb
77
+ - spec/smart_ioc/example/admins/repository/admins_repository.rb
78
+ - spec/smart_ioc/example/admins/repository/test/admins_repository.rb
79
+ - spec/smart_ioc/example/users/repository/users_dao.rb
80
+ - spec/smart_ioc/example/users/repository/users_repository.rb
81
+ - spec/smart_ioc/example/users/services/users_creator.rb
82
+ - spec/smart_ioc/example/users/user.rb
83
+ - spec/smart_ioc/example/utils/config.rb
84
+ - spec/smart_ioc/example/utils/logger.rb
85
+ - spec/smart_ioc/object_spec.rb
86
+ - spec/smart_ioc/smart_ioc_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://github.com/droidlabs/smart_ioc
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Inversion of Control Container
112
+ test_files:
113
+ - spec/smart_ioc/bean_definition_spec.rb
114
+ - spec/smart_ioc/bean_locator_spec.rb
115
+ - spec/smart_ioc/example/admins/repository/admins_dao.rb
116
+ - spec/smart_ioc/example/admins/repository/admins_repository.rb
117
+ - spec/smart_ioc/example/admins/repository/test/admins_repository.rb
118
+ - spec/smart_ioc/example/users/repository/users_dao.rb
119
+ - spec/smart_ioc/example/users/repository/users_repository.rb
120
+ - spec/smart_ioc/example/users/services/users_creator.rb
121
+ - spec/smart_ioc/example/users/user.rb
122
+ - spec/smart_ioc/example/utils/config.rb
123
+ - spec/smart_ioc/example/utils/logger.rb
124
+ - spec/smart_ioc/object_spec.rb
125
+ - spec/smart_ioc/smart_ioc_spec.rb
126
+ - spec/spec_helper.rb