smart_ioc 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/smart_ioc.rb +2 -1
- data/lib/smart_ioc/bean_factory.rb +2 -0
- data/lib/smart_ioc/bean_file_loader.rb +7 -1
- data/lib/smart_ioc/container.rb +13 -3
- data/lib/smart_ioc/version.rb +1 -1
- data/spec/smart_ioc/bean_file_loader_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2067f3974f1412037425a8615dd9143091f06ef
|
4
|
+
data.tar.gz: 9ab33bd6d8a554bf1e77ad0a85bc04e7e8a6fb45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3415af0ff931fd21404f6e91ade5367c025395ce739cd05bfc2f98db175f5c60df36690e6e8f1b419ee10e2355e0f90ac0a7b113e4e4735c20f2de7d43f7999
|
7
|
+
data.tar.gz: 82dc65927d8e00b79ae790e4f65b55f13f6adf3a19103024a0b810ec41ada75e662413d6705be8b72527541b950dccf03a33deca453cbe0d5ea419d05ee8c14f
|
data/lib/smart_ioc.rb
CHANGED
@@ -54,6 +54,7 @@ module SmartIoC
|
|
54
54
|
extend Forwardable
|
55
55
|
|
56
56
|
def_delegators :container, :register_bean, :get_bean_definition_by_class,
|
57
|
-
:set_extra_context_for_package, :get_bean, :clear_scopes,
|
57
|
+
:set_extra_context_for_package, :get_bean, :clear_scopes,
|
58
|
+
:force_clear_scopes, :set_load_proc
|
58
59
|
end
|
59
60
|
end
|
@@ -3,6 +3,8 @@ class SmartIoC::BeanFactory
|
|
3
3
|
include SmartIoC::Errors
|
4
4
|
include SmartIoC::Args
|
5
5
|
|
6
|
+
attr_reader :bean_file_loader
|
7
|
+
|
6
8
|
def initialize(bean_definitions_storage, extra_package_contexts)
|
7
9
|
@bean_definitions_storage = bean_definitions_storage
|
8
10
|
@extra_package_contexts = extra_package_contexts
|
@@ -1,6 +1,12 @@
|
|
1
1
|
class SmartIoC::BeanFileLoader
|
2
2
|
def initialize
|
3
3
|
@loaded_locations = {}
|
4
|
+
@load_proc = Proc.new { |location| load(location) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_load_proc(&block)
|
8
|
+
raise ArgumentError, "block should be given" unless block_given?
|
9
|
+
@load_proc = block
|
4
10
|
end
|
5
11
|
|
6
12
|
# @param bean_name [Symbol] bean name
|
@@ -11,7 +17,7 @@ class SmartIoC::BeanFileLoader
|
|
11
17
|
locations.each do |location|
|
12
18
|
next if @loaded_locations.has_key?(location)
|
13
19
|
@loaded_locations[location] = true
|
14
|
-
|
20
|
+
@load_proc.call(location)
|
15
21
|
end
|
16
22
|
|
17
23
|
nil
|
data/lib/smart_ioc/container.rb
CHANGED
@@ -2,7 +2,7 @@ module SmartIoC
|
|
2
2
|
# SmartIoC::Container is a beans store used for dependency injection
|
3
3
|
class Container
|
4
4
|
include SmartIoC::Args
|
5
|
-
|
5
|
+
|
6
6
|
DEFAULT_CONTEXT = :default
|
7
7
|
|
8
8
|
class << self
|
@@ -32,14 +32,14 @@ module SmartIoC
|
|
32
32
|
def register_bean(bean_name:, klass:, context:, scope:, path:,
|
33
33
|
factory_method: nil, package_name: nil, instance: true)
|
34
34
|
context ||= DEFAULT_CONTEXT
|
35
|
-
|
35
|
+
|
36
36
|
check_arg(bean_name, :bean_name, Symbol)
|
37
37
|
check_arg(context, :context, Symbol)
|
38
38
|
check_arg(klass, :klass, Class)
|
39
39
|
check_arg(path, :path, String)
|
40
40
|
check_arg(factory_method, :factory_method, Symbol) if factory_method
|
41
41
|
check_arg_any(instance, :instance, [TrueClass, FalseClass])
|
42
|
-
|
42
|
+
|
43
43
|
scope ||= SmartIoC::Scopes::Singleton::VALUE
|
44
44
|
|
45
45
|
allowed_scopes = [
|
@@ -88,6 +88,16 @@ module SmartIoC
|
|
88
88
|
bean_definitions_storage.find_by_class(klass)
|
89
89
|
end
|
90
90
|
|
91
|
+
# Sets new load proc
|
92
|
+
# for those who use active support dependency loader
|
93
|
+
# one can use
|
94
|
+
# SmartIoC.set_load_proc do |location|
|
95
|
+
# require_dependency(location)
|
96
|
+
# end
|
97
|
+
def set_load_proc(&proc)
|
98
|
+
bean_factory.bean_file_loader.set_load_proc(&proc)
|
99
|
+
end
|
100
|
+
|
91
101
|
# Sets extra context for specific package
|
92
102
|
# @param package_name [Symbol] package name
|
93
103
|
# @param context [Symbol] context (ex: :test)
|
data/lib/smart_ioc/version.rb
CHANGED
@@ -10,9 +10,24 @@ describe SmartIoC::BeanFileLoader do
|
|
10
10
|
dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/utils')
|
11
11
|
SmartIoC.find_package_beans(:utils, dir_path)
|
12
12
|
|
13
|
+
dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/users')
|
14
|
+
SmartIoC.find_package_beans(:users, dir_path)
|
15
|
+
|
13
16
|
@container = SmartIoC.container
|
14
17
|
end
|
15
18
|
|
19
|
+
it 'sets load proc' do
|
20
|
+
$location_loaded = false
|
21
|
+
|
22
|
+
@container.set_load_proc do |location|
|
23
|
+
$location_loaded = true
|
24
|
+
load(location)
|
25
|
+
end
|
26
|
+
|
27
|
+
@container.get_bean(:users_creator)
|
28
|
+
expect($location_loaded).to eq(true)
|
29
|
+
end
|
30
|
+
|
16
31
|
it 'requires beans only once' do
|
17
32
|
repository = @container.get_bean(:repository, package: :admins, context: :test)
|
18
33
|
repository = @container.get_bean(:repository, package: :admins, context: :test)
|
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.22
|
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-03-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|