smart_ioc 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -2
- data/Gemfile.lock +28 -10
- data/README.md +95 -79
- data/docs/_config.yml +1 -0
- data/docs/index.md +114 -0
- data/lib/smart_ioc/version.rb +1 -1
- data/smart_ioc.gemspec +1 -0
- data/spec/spec_helper.rb +10 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5397abe56282d5f41ac3b7cef502fa15e7fd457e
|
4
|
+
data.tar.gz: 6eb3ea3abaaa91cf5fd1a93689d6109ba81862ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d799e2feb6a443305967f86e9201ee41ca3a10a68514d8b0817dc646fe333dc03ed062c55ee58221e8f67400d99c17df7cb61d1ad027874eda137272cf34ad
|
7
|
+
data.tar.gz: f447b52709d6f414fc596c9f6f55b9f93f5a1ee2671c4b658a094fad0bd5b2a66e4582dfe26df19d2f4f4b9c9dd559630ad21b6c51ae6ec69e90c1f424e58db3
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_ioc (0.1.
|
4
|
+
smart_ioc (0.1.19)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
byebug (9.0.6)
|
10
|
+
codecov (0.1.9)
|
11
|
+
json
|
12
|
+
simplecov
|
13
|
+
url
|
10
14
|
diff-lcs (1.2.5)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rspec-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
docile (1.1.5)
|
16
|
+
json (2.0.2)
|
17
|
+
rake (12.0.0)
|
18
|
+
rspec (3.5.0)
|
19
|
+
rspec-core (~> 3.5.0)
|
20
|
+
rspec-expectations (~> 3.5.0)
|
21
|
+
rspec-mocks (~> 3.5.0)
|
22
|
+
rspec-core (3.5.4)
|
23
|
+
rspec-support (~> 3.5.0)
|
24
|
+
rspec-expectations (3.5.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.5.0)
|
27
|
+
rspec-mocks (3.5.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.5.0)
|
30
|
+
rspec-support (3.5.0)
|
31
|
+
simplecov (0.12.0)
|
32
|
+
docile (~> 1.1.0)
|
33
|
+
json (>= 1.8, < 3)
|
34
|
+
simplecov-html (~> 0.10.0)
|
35
|
+
simplecov-html (0.10.0)
|
36
|
+
url (0.3.2)
|
20
37
|
|
21
38
|
PLATFORMS
|
22
39
|
ruby
|
@@ -24,6 +41,7 @@ PLATFORMS
|
|
24
41
|
DEPENDENCIES
|
25
42
|
bundler (~> 1.3)
|
26
43
|
byebug
|
44
|
+
codecov
|
27
45
|
rake
|
28
46
|
rspec
|
29
47
|
smart_ioc!
|
data/README.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# SmartIoC
|
2
|
+
[![Build Status](https://travis-ci.org/ddd-ruby/smart_ioc.png)](https://travis-ci.org/ddd-ruby/smart_ioc)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/ddd-ruby/smart_ioc/badges/gpa.svg)](https://codeclimate.com/github/ddd-ruby/smart_ioc)
|
4
|
+
[![codecov](https://codecov.io/gh/ddd-ruby/smart_ioc/branch/master/graph/badge.svg)](https://codecov.io/gh/ddd-ruby/smart_ioc)
|
5
|
+
[![Dependency Status](https://gemnasium.com/ddd-ruby/smart_ioc.png)](https://gemnasium.com/ddd-ruby/smart_ioc)
|
6
|
+
|
7
|
+
|
1
8
|
SmartIoC is a smart and really simple IoC container for Ruby applications.
|
2
9
|
|
3
10
|
## Installation
|
@@ -6,93 +13,102 @@ SmartIoC is a smart and really simple IoC container for Ruby applications.
|
|
6
13
|
## Setup
|
7
14
|
Set package name and source package folder with beans. SmartIoC will parse source files and detect bean definitions automatically for you.
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
```ruby
|
17
|
+
SmartIoC.find_package_beans(:PACKAGE_NAME, File.dirname(__FILE__))
|
18
|
+
```
|
12
19
|
|
13
|
-
|
20
|
+
If you have several packages in your application (like if you are using [rdm package manager](https://github.com/droidlabs/rdm)) you can run SmartIoC.find_package_beans several time pointing it to the source folder and setting a different package name.
|
14
21
|
|
15
22
|
## Basic information
|
16
23
|
1. Different packages can use beans with same name.
|
17
24
|
2. For a specific package you can declare beans with same name if they have different context.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
25
|
+
```ruby
|
26
|
+
class UsersRepository
|
27
|
+
include SmartIoC::Iocify
|
28
|
+
bean :users_repository
|
29
|
+
end
|
30
|
+
|
31
|
+
class Test::UsersRepository
|
32
|
+
include SmartIoC::Iocify
|
33
|
+
bean :users_repository, context: :test
|
34
|
+
end
|
35
|
+
```
|
36
|
+
3. You can extend the `:default` context with any other in the following way:
|
37
|
+
```ruby
|
38
|
+
SmartIoC::Container.get_instance.set_extra_context_for_package(:YOUR_PACKAGE_NAME, :test)
|
39
|
+
```
|
40
|
+
|
41
|
+
This allows to create test implementations for any package dependency.
|
42
|
+
|
43
|
+
4. In order to get a bean use `SmartIoC::Container.get_bean(:BEAN_NAME, package: :PACKAGE_NAME, context: :default)`. `package` and `context` are optional arguments.
|
44
|
+
|
45
|
+
5. If you use the same bean name for different dependencies in different packages you will need to specify the package directly. You can do that by using `from` parameter:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class UsersCreator
|
49
|
+
include SmartIoC::Iocify
|
50
|
+
bean :users_creator
|
51
|
+
|
52
|
+
inject :users_repository, from: :repositories
|
53
|
+
|
54
|
+
def create
|
55
|
+
user = User.new
|
56
|
+
users_repository.put(user)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
6. To have a diffent local name for a specific bean use the `ref` parameter.
|
63
|
+
In the following example we are injecting the `:users_repository` dependency but refer to it as `repo` locally.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class UsersCreator
|
67
|
+
include SmartIoC::Iocify
|
68
|
+
bean :users_creator
|
69
|
+
|
70
|
+
inject :users_repository, ref: :repo, from: :repositories
|
71
|
+
|
72
|
+
def create
|
73
|
+
user = User.new
|
74
|
+
repo.put(user)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
7. Use factory method to instantiate the bean via a special creational method
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class RepositoryFactory
|
83
|
+
include SmartIoC::Iocify
|
84
|
+
bean :users_creator, factory_method: :get_bean
|
85
|
+
|
86
|
+
inject :config
|
87
|
+
inject :users_repository
|
88
|
+
inject :admins_repository
|
89
|
+
|
90
|
+
def get_bean
|
91
|
+
if config.admin_access?
|
92
|
+
admins_repository
|
93
|
+
else
|
94
|
+
users_repository
|
22
95
|
end
|
96
|
+
end
|
23
97
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
SmartIoC::Container.get_instance.set_extra_context_for_package(:YOUR_PACKAGE_NAME, :test)
|
33
|
-
```
|
34
|
-
This allows to create test implementations that for any package dependencies.
|
35
|
-
4. In order to get bean use `SmartIoC::Container.get_bean(:BEAN_NAME, package: :PACKAGE_NAME, context: :default)`. `package` and `context` are optional arguments.
|
36
|
-
5. If you have name with same bean in different packages you will need to set package directly. You can simply do that in the following way:
|
37
|
-
```ruby
|
38
|
-
class UsersCreator
|
39
|
-
include SmartIoC::Iocify
|
40
|
-
bean :users_creator
|
41
|
-
|
42
|
-
inject :users_repository, from: :repositories
|
43
|
-
|
44
|
-
def create
|
45
|
-
user = User.new
|
46
|
-
users_repository.put(user)
|
47
|
-
end
|
98
|
+
def create
|
99
|
+
user = User.new
|
100
|
+
repo.put(user)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
48
104
|
|
49
|
-
end
|
50
|
-
```
|
51
|
-
6. Change dependency name inside your bean:
|
52
|
-
```ruby
|
53
|
-
class UsersCreator
|
54
|
-
include SmartIoC::Iocify
|
55
|
-
bean :users_creator
|
56
|
-
|
57
|
-
inject :repo, ref: :users_repository, from: :repositories
|
58
|
-
|
59
|
-
def create
|
60
|
-
user = User.new
|
61
|
-
repo.put(user)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
```
|
65
|
-
7. Use factory method to instantiate the bean
|
66
|
-
```ruby
|
67
|
-
class RepositoryFactory
|
68
|
-
include SmartIoC::Iocify
|
69
|
-
bean :users_creator, factory_method: :get_bean
|
70
|
-
|
71
|
-
inject :config
|
72
|
-
inject :users_repository
|
73
|
-
inject :admins_repository
|
74
|
-
|
75
|
-
def get_bean
|
76
|
-
if config.admin_access?
|
77
|
-
admins_repository
|
78
|
-
else
|
79
|
-
users_repository
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def create
|
84
|
-
user = User.new
|
85
|
-
repo.put(user)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
```
|
89
105
|
8. Class level beans (object will not be instantiated and class will be used for that bean instead). Set `instance: false`:
|
90
106
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
107
|
+
```ruby
|
108
|
+
class UsersCreator
|
109
|
+
include SmartIoC::Iocify
|
110
|
+
bean :users_creator, instance: false
|
95
111
|
|
96
|
-
|
97
|
-
|
98
|
-
|
112
|
+
inject :users_repository
|
113
|
+
end
|
114
|
+
```
|
data/docs/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-minimal
|
data/docs/index.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# SmartIoC
|
2
|
+
[![Build Status](https://travis-ci.org/ddd-ruby/smart_ioc.png)](https://travis-ci.org/ddd-ruby/smart_ioc)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/ddd-ruby/smart_ioc/badges/gpa.svg)](https://codeclimate.com/github/ddd-ruby/smart_ioc)
|
4
|
+
[![codecov](https://codecov.io/gh/ddd-ruby/smart_ioc/branch/master/graph/badge.svg)](https://codecov.io/gh/ddd-ruby/smart_ioc)
|
5
|
+
[![Dependency Status](https://gemnasium.com/ddd-ruby/smart_ioc.png)](https://gemnasium.com/ddd-ruby/smart_ioc)
|
6
|
+
|
7
|
+
|
8
|
+
SmartIoC is a smart and really simple IoC container for Ruby applications.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
`gem install smart_ioc`
|
12
|
+
|
13
|
+
## Setup
|
14
|
+
Set package name and source package folder with beans. SmartIoC will parse source files and detect bean definitions automatically for you.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
SmartIoC.find_package_beans(:PACKAGE_NAME, File.dirname(__FILE__))
|
18
|
+
```
|
19
|
+
|
20
|
+
If you have several packages in your application (like if you are using [rdm package manager](https://github.com/droidlabs/rdm)) you can run SmartIoC.find_package_beans several time pointing it to the source folder and setting a different package name.
|
21
|
+
|
22
|
+
## Basic information
|
23
|
+
1. Different packages can use beans with same name.
|
24
|
+
2. For a specific package you can declare beans with same name if they have different context.
|
25
|
+
```ruby
|
26
|
+
class UsersRepository
|
27
|
+
include SmartIoC::Iocify
|
28
|
+
bean :users_repository
|
29
|
+
end
|
30
|
+
|
31
|
+
class Test::UsersRepository
|
32
|
+
include SmartIoC::Iocify
|
33
|
+
bean :users_repository, context: :test
|
34
|
+
end
|
35
|
+
```
|
36
|
+
3. You can extend the `:default` context with any other in the following way:
|
37
|
+
```ruby
|
38
|
+
SmartIoC::Container.get_instance.set_extra_context_for_package(:YOUR_PACKAGE_NAME, :test)
|
39
|
+
```
|
40
|
+
|
41
|
+
This allows to create test implementations for any package dependency.
|
42
|
+
|
43
|
+
4. In order to get a bean use `SmartIoC::Container.get_bean(:BEAN_NAME, package: :PACKAGE_NAME, context: :default)`. `package` and `context` are optional arguments.
|
44
|
+
|
45
|
+
5. If you use the same bean name for different dependencies in different packages you will need to specify the package directly. You can do that by using `from` parameter:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class UsersCreator
|
49
|
+
include SmartIoC::Iocify
|
50
|
+
bean :users_creator
|
51
|
+
|
52
|
+
inject :users_repository, from: :repositories
|
53
|
+
|
54
|
+
def create
|
55
|
+
user = User.new
|
56
|
+
users_repository.put(user)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
6. To have a diffent local name for a specific bean use the `ref` parameter.
|
63
|
+
In the following example we are injecting the `:users_repository` dependency but refer to it as `repo` locally.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class UsersCreator
|
67
|
+
include SmartIoC::Iocify
|
68
|
+
bean :users_creator
|
69
|
+
|
70
|
+
inject :users_repository, ref: :repo, from: :repositories
|
71
|
+
|
72
|
+
def create
|
73
|
+
user = User.new
|
74
|
+
repo.put(user)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
7. Use factory method to instantiate the bean via a special creational method
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class RepositoryFactory
|
83
|
+
include SmartIoC::Iocify
|
84
|
+
bean :users_creator, factory_method: :get_bean
|
85
|
+
|
86
|
+
inject :config
|
87
|
+
inject :users_repository
|
88
|
+
inject :admins_repository
|
89
|
+
|
90
|
+
def get_bean
|
91
|
+
if config.admin_access?
|
92
|
+
admins_repository
|
93
|
+
else
|
94
|
+
users_repository
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def create
|
99
|
+
user = User.new
|
100
|
+
repo.put(user)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
8. Class level beans (object will not be instantiated and class will be used for that bean instead). Set `instance: false`:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
class UsersCreator
|
109
|
+
include SmartIoC::Iocify
|
110
|
+
bean :users_creator, instance: false
|
111
|
+
|
112
|
+
inject :users_repository
|
113
|
+
end
|
114
|
+
```
|
data/lib/smart_ioc/version.rb
CHANGED
data/smart_ioc.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/spec/"
|
6
|
+
add_filter "/.direnv/"
|
7
|
+
end
|
8
|
+
if ENV['CI']=='true'
|
9
|
+
require 'codecov'
|
10
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
11
|
+
end
|
12
|
+
|
3
13
|
require 'smart_ioc'
|
4
14
|
require 'byebug'
|
5
15
|
|
6
16
|
RSpec.configure do |config|
|
7
|
-
config.color_enabled = true
|
8
17
|
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.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruslan Gatiyatov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Inversion of Control Container
|
42
56
|
email:
|
43
57
|
- ruslan@droidlabs.pro
|
@@ -53,6 +67,8 @@ files:
|
|
53
67
|
- LICENSE.txt
|
54
68
|
- README.md
|
55
69
|
- Rakefile
|
70
|
+
- docs/_config.yml
|
71
|
+
- docs/index.md
|
56
72
|
- lib/smart_ioc.rb
|
57
73
|
- lib/smart_ioc/bean_definition.rb
|
58
74
|
- lib/smart_ioc/bean_definitions_storage.rb
|