smart_ioc 0.1.14 → 0.1.16

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: 711973dfcc378ef2747687d59998356f9221ea1f
4
- data.tar.gz: b452d155c41eca11c6fec9d4ecb10b49644c4081
3
+ metadata.gz: 22a096006f50dc11ad6e43dd7121b6a07cde42b4
4
+ data.tar.gz: a30fd7330b05bcabcb3af0312e92e1787f8f6b3b
5
5
  SHA512:
6
- metadata.gz: d8862d38fa0de781c29ca63295c263339be7e44582b9c076ea07411e74be9ea80aa151cb0f4f4fa98e0c5fb35e0b81026ff3b69d2e16af6ef09bdbf15cf64182
7
- data.tar.gz: b0793c5eccf9f883ffbf2aa2fe1116e55caa74cc4ada9c564b1cf3b679bccc25038b316db7917edbbb36dd06b59e6ead4fb92da4bc856294dbf29c9c92443809
6
+ metadata.gz: ab86b19a3d729377f12dc2db706e59441286f330fd179635d8f9a0237a37662c5dc5b256e5251ecaedce2b9c9d0ed620394ab3b2a29642a93155b2b33647dbd9
7
+ data.tar.gz: 364ee6a73908179074a21345ab4ffbfe4211d2828720c8ffc496da74278647f38a0365ef7b948ffb8e60c846d4e7984e8e2a5e78fc1bc0c7e1fc174ceeb48ce6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_ioc (0.1.14)
4
+ smart_ioc (0.1.16)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -17,10 +17,12 @@ SmartIoC is a smart and really simple IoC container for Ruby applications.
17
17
  2. For a specific package you can declare beans with same name if they have different context.
18
18
  ```ruby
19
19
  class UsersRepository
20
+ include SmartIoC::Iocify
20
21
  bean :users_repository
21
22
  end
22
23
 
23
24
  class Test::UsersRepository
25
+ include SmartIoC::Iocify
24
26
  bean :users_repository, context: :test
25
27
  end
26
28
  ```
@@ -34,6 +36,7 @@ This allows to create test implementations that for any package dependencies.
34
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:
35
37
  ```ruby
36
38
  class UsersCreator
39
+ include SmartIoC::Iocify
37
40
  bean :users_creator
38
41
 
39
42
  inject :users_repository, from: :repositories
@@ -48,6 +51,7 @@ This allows to create test implementations that for any package dependencies.
48
51
  6. Change dependency name inside your bean:
49
52
  ```ruby
50
53
  class UsersCreator
54
+ include SmartIoC::Iocify
51
55
  bean :users_creator
52
56
 
53
57
  inject :repo, ref: :users_repository, from: :repositories
@@ -61,6 +65,7 @@ This allows to create test implementations that for any package dependencies.
61
65
  7. Use factory method to instantiate the bean
62
66
  ```ruby
63
67
  class RepositoryFactory
68
+ include SmartIoC::Iocify
64
69
  bean :users_creator, factory_method: :get_bean
65
70
 
66
71
  inject :config
@@ -85,7 +90,9 @@ This allows to create test implementations that for any package dependencies.
85
90
 
86
91
  ```ruby
87
92
  class UsersCreator
93
+ include SmartIoC::Iocify
88
94
  bean :users_creator, instance: false
95
+
89
96
  inject :users_repository
90
97
  end
91
98
  ```
@@ -24,7 +24,15 @@ class SmartIoC::BeanFactory
24
24
  # @return bean instance
25
25
  # @raise [ArgumentError] if bean is not found
26
26
  # @raise [ArgumentError] if ambiguous bean definition was found
27
- def get_bean(bean_name, package: nil, context: SmartIoC::Container::DEFAULT_CONTEXT)
27
+ def get_bean(bean_name, package: nil, context: nil)
28
+ context ||= if package
29
+ @extra_package_contexts.get_context(package)
30
+ else
31
+ @bean_file_loader.require_bean(bean_name)
32
+ bean_definition = autodetect_bean_definition(bean_name, package, nil)
33
+ bean_definition.context
34
+ end
35
+
28
36
  if !context.is_a?(Symbol)
29
37
  raise ArgumentError, 'context should be a Symbol'
30
38
  end
@@ -12,7 +12,7 @@ module SmartIoC
12
12
  @container = nil
13
13
  end
14
14
 
15
- def get_bean(bean_name, package: nil, context: SmartIoC::Container::DEFAULT_CONTEXT)
15
+ def get_bean(bean_name, package: nil, context: nil)
16
16
  get_instance.get_bean(bean_name, package: package, context: context)
17
17
  end
18
18
  end
@@ -114,7 +114,7 @@ module SmartIoC
114
114
  # @param optional package [Symbol] package name
115
115
  # @param optional context [Symbol] package context
116
116
  # @return bean instance from container
117
- def get_bean(bean_name, package: nil, context: SmartIoC::Container::DEFAULT_CONTEXT)
117
+ def get_bean(bean_name, package: nil, context: nil)
118
118
  bean_factory.get_bean(bean_name, package: package, context: context)
119
119
  end
120
120
 
@@ -1,3 +1,3 @@
1
1
  module SmartIoC
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SmartIoC::BeanFactory do
4
+ class Repo
5
+ include SmartIoC::Iocify
6
+ bean :repo, context: :default, package: :bean_factory
7
+ end
8
+
9
+ class TestRepo
10
+ include SmartIoC::Iocify
11
+ bean :repo, context: :test, package: :bean_factory
12
+ end
13
+
14
+ it 'returns proper bean for test context' do
15
+ SmartIoC::Container.get_instance.set_extra_context_for_package(:bean_factory, :test)
16
+ expect(SmartIoC::Container.get_bean(:repo)).to be_a(TestRepo)
17
+ end
18
+
19
+ it 'returns proper bean for default context' do
20
+ SmartIoC::Container.get_instance.set_extra_context_for_package(:bean_factory, :default)
21
+ expect(SmartIoC::Container.get_bean(:repo)).to be_a(Repo)
22
+ end
23
+ 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.14
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - lib/smart_ioc/version.rb
73
73
  - smart_ioc.gemspec
74
74
  - spec/smart_ioc/bean_definition_spec.rb
75
+ - spec/smart_ioc/bean_factory_spec.rb
75
76
  - spec/smart_ioc/bean_locator_spec.rb
76
77
  - spec/smart_ioc/example/admins/repository/admins_dao.rb
77
78
  - spec/smart_ioc/example/admins/repository/admins_repository.rb
@@ -111,6 +112,7 @@ specification_version: 4
111
112
  summary: Inversion of Control Container
112
113
  test_files:
113
114
  - spec/smart_ioc/bean_definition_spec.rb
115
+ - spec/smart_ioc/bean_factory_spec.rb
114
116
  - spec/smart_ioc/bean_locator_spec.rb
115
117
  - spec/smart_ioc/example/admins/repository/admins_dao.rb
116
118
  - spec/smart_ioc/example/admins/repository/admins_repository.rb