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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c7072e73dc2252039b8c04abc90aadbbf75c773
4
- data.tar.gz: ee3f8369255712f3f5263767f276a383e8606420
3
+ metadata.gz: 5397abe56282d5f41ac3b7cef502fa15e7fd457e
4
+ data.tar.gz: 6eb3ea3abaaa91cf5fd1a93689d6109ba81862ac
5
5
  SHA512:
6
- metadata.gz: 6787d8889e1b732a0504b985420586554011fc7f4771a633172d66ca8b4c390bddea636524b33207ae086e0877c2ce3548d90a276bc3c9aa36fadf5954723533
7
- data.tar.gz: b5007f88e1a4cc16e9410e737d488c0a85c5ae21a0a3b76800348936e518755318503b2d16c27209de7013d9cbccb139f593a13b6ce9bea1c2c7281a7f8dfe88
6
+ metadata.gz: 90d799e2feb6a443305967f86e9201ee41ca3a10a68514d8b0817dc646fe333dc03ed062c55ee58221e8f67400d99c17df7cb61d1ad027874eda137272cf34ad
7
+ data.tar.gz: f447b52709d6f414fc596c9f6f55b9f93f5a1ee2671c4b658a094fad0bd5b2a66e4582dfe26df19d2f4f4b9c9dd559630ad21b6c51ae6ec69e90c1f424e58db3
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ tags
4
4
  .DS_Store
5
5
  pkg
6
6
  .byebug_history
7
+ coverage/
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  rvm:
2
- - 2.0.0
3
- script: "bundle exec rspec spec/"
2
+ - 2.2.0
3
+ - 2.3.0
4
+ - 2.4.0
5
+ script:
6
+ - "gem install bundler"
7
+ - "bundle exec rspec spec/"
data/Gemfile.lock CHANGED
@@ -1,22 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.1.17)
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
- rake (10.1.1)
12
- rspec (2.14.1)
13
- rspec-core (~> 2.14.0)
14
- rspec-expectations (~> 2.14.0)
15
- rspec-mocks (~> 2.14.0)
16
- rspec-core (2.14.7)
17
- rspec-expectations (2.14.4)
18
- diff-lcs (>= 1.1.3, < 2.0)
19
- rspec-mocks (2.14.4)
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
- ```ruby
10
- SmartIoC.find_package_beans(:PACKAGE_NAME, File.dirname(__FILE__))
11
- ```
16
+ ```ruby
17
+ SmartIoC.find_package_beans(:PACKAGE_NAME, File.dirname(__FILE__))
18
+ ```
12
19
 
13
- If you have saveral 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 source folder and setting different package name.
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
- ```ruby
19
- class UsersRepository
20
- include SmartIoC::Iocify
21
- bean :users_repository
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
- class Test::UsersRepository
25
- include SmartIoC::Iocify
26
- bean :users_repository, context: :test
27
- end
28
- ```
29
- 3. You can extend `:default` context with any other in the following way:
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
- ```ruby
92
- class UsersCreator
93
- include SmartIoC::Iocify
94
- bean :users_creator, instance: false
107
+ ```ruby
108
+ class UsersCreator
109
+ include SmartIoC::Iocify
110
+ bean :users_creator, instance: false
95
111
 
96
- inject :users_repository
97
- end
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
+ ```
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
data/smart_ioc.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency "codecov"
23
24
  end
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.18
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-09 00:00:00.000000000 Z
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